Trigger on Update Firebird

余生长醉 提交于 2019-12-13 05:42:37

问题


Whenever the field sync is updated without the flag being YES I need to set that field to NULL.

CREATE TRIGGER my_trigger FOR customers
AFTER UPDATE
as
BEGIN
if(new.sync <> 'YES')
  then new.sync = NULL;
end

But I keep receiving the error:

Dynamic SQL Error SQL error code = -104 Unexpected end of command - line 6, column 26

I believe line 6 is then new.sync = NULL? I thought the problem might be the use of ; but it's not, because if I remove it then it gives the same error but in the line 7.


回答1:


Solved.

Some code was missing but besides that also the logic. I needed to used BEFORE and not AFTER.

SET TERM !; 
CREATE TRIGGER my_trigger FOR customers 
BEFORE UPDATE 
POSITION 0 
AS BEGIN 
    IF(new.sync <> 'YES') THEN BEGIN 
        new.sync = NULL; 
    END
END;


来源:https://stackoverflow.com/questions/28362568/trigger-on-update-firebird

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!