我正在尝试编写一个触发器,如下面的简化示例所示:
create trigger adr_trg update of fname, lname on adr
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
(
IF o.fname <> n.fname THEN
insert into adrlog (old_value, new_value)
values (o.fname, n.fname);
END IF;
IF o.lname <> n.lname THEN
insert into adrlog (old_value, new_value)
values (o.lname, n.lname);
END IF;
)
这失败了!
只有这样才有效:
create trigger adr_trg update of fname, lname on adr
REFERENCING OLD AS o NEW AS n
FOR EACH ROW
(
insert into adrlog (old_value, new_value)
values (o.fname, n.fname);
)
我做错了什么?
答案 0 :(得分:3)
我认为你应该用IF-THEN逻辑编写一个存储过程,然后从这个触发器中调用它。我认为触发器只支持简单的SQL语句,而不支持SPL语句
编辑:
CREATE PROCEDURE proc1()
REFERENCING OLD AS o NEW AS n FOR tab1;
....your logic
CREATE TRIGGER adr_trg update of fname, lname on adr
REFERENCING OLD AS o NEW AS n
FOR EACH ROW(EXECUTE PROCEDURE proc1() WITH TRIGGER REFERENCES);
答案 1 :(得分:3)
老问题,但没有得到很好的回答,以防有人像我一样在这里降落。
Informix处理所请求的功能,但语法不同:
create trigger adr_trg update of fname,lname on adr
referencing old as o new as n
for each row
when ( o.fname != n.fname )
(
insert into adrlog (old_value,new_value)
values (o.fname,n.fname)
) ,
when ( o.lname != n.lname )
(
insert into adrlog (old_value,new_value)
values (o.lname,n.lname)
)
;