请告诉我代码有什么问题。无法找到错误
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 ;
答案 0 :(得分: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。”