0

请告诉我代码有什么问题。无法解决错误

DELIMITER $$
CREATE TRIGGER update_status  BEFORE Update ON listing_basic_new_updated 
FOR EACH ROW
 if new.processing_status is not null 
    then begin
    SET new.rep_status = New.processing_status;
    end; 
  elseif new.televeri_status is not null 
    then begin
    SET new.rep_status = New.televeri_status;
    end; 
  elseif new.verification_status is not null 
    then begin
    SET new.rep_status = New.verification_status;
    end;
end if;
END$$
DELIMITER ;
4

1 回答 1

1

我认为你错过了一个BEGIN与你最后相匹配END的:

DELIMITER $$
CREATE TRIGGER update_status  BEFORE Update ON listing_basic_new_updated 
FOR EACH ROW
BEGIN
 if new.processing_status is not null 
    then begin
    SET new.rep_status = New.processing_status;
    end; 
  elseif new.televeri_status is not null 
    then begin
    SET new.rep_status = New.televeri_status;
    end; 
  elseif new.verification_status is not null 
    then begin
    SET new.rep_status = New.verification_status;
    end;
end if;
END$$
DELIMITER ;

我想你也许可以用

SET new.rep_status = COALESCE(new.processing_status, new.televeri_status,
                           new.verification_status, new.rep_status);

COALESCE:“返回列表中的第一个非 NULL 值,如果没有非 NULL 值,则返回 NULL。”

于 2013-04-18T06:31:07.763 回答