gpt4 book ai didi

sql - 如何在 informix 中创建触发器?

转载 作者:搜寻专家 更新时间:2023-10-30 20:02:41 26 4
gpt4 key购买 nike

我正在尝试编写一个触发器,如下面的简化示例所示:

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);
)

我做错了什么?

最佳答案

我认为您应该使用 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);

关于sql - 如何在 informix 中创建触发器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8577176/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com