简单的预言机触发器
简单的一个。我是 PLSql 的新手,oracle 的错误消息从来没有太大帮助。
我想做一个简单的触发器来更新当前日期的列,即表的“修改日期”列。但出现了一个奇怪的错误。
这个想法很简单,
create table test1 (tcol varchar2(255), tcol2 varchar2(255))
CREATE OR REPLACE TRIGGER testTRG
AFTER INSERT OR UPDATE ON test1
FOR EACH ROW
BEGIN
update test1
set tcol2 = to_char(sysdate)
where tcol = :OLD.tcol;
END;
insert into test1 (tcol) values ('test1');
这会弹出错误:
ORA-04091: table RAIDBIDAT_OWN.TEST1 is mutating, trigger/function may not see it
ORA-06512: at "RAIDBIDAT_OWN.TESTTRG", line 2
ORA-04088: error during execution of trigger 'RAIDBIDAT_OWN.TESTTRG'
有人能快速解决这个问题吗?
谢尔斯、
F.
Simple one. I´m a bit of a newvbie with PLSql and oracle's error messages are never too helpful.
I want to do a simple trigger to update a column with the current date i.e. 'modified date' column of a table. Getting an odd error though.
The idea is simple
create table test1 (tcol varchar2(255), tcol2 varchar2(255))
CREATE OR REPLACE TRIGGER testTRG
AFTER INSERT OR UPDATE ON test1
FOR EACH ROW
BEGIN
update test1
set tcol2 = to_char(sysdate)
where tcol = :OLD.tcol;
END;
insert into test1 (tcol) values ('test1');
this pops up the error:
ORA-04091: table RAIDBIDAT_OWN.TEST1 is mutating, trigger/function may not see it
ORA-06512: at "RAIDBIDAT_OWN.TESTTRG", line 2
ORA-04088: error during execution of trigger 'RAIDBIDAT_OWN.TESTTRG'
Would anyone have a quick solution for this?
cheers,
f.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的情况:
托尼的建议几乎是正确的,但不幸的是它无法编译:
因为您只能在每行触发器之前更改新值:
问候,
抢。
Your situation:
Tony's suggestion is almost right, but unfortunately it doesn't compile:
Because you can only change NEW values in before-each-row triggers:
Regards,
Rob.
触发器应该简单地写为:
不需要发出同一行的另一个更新(正如您所发现的,您不能)。
更常见的是使用 DATE 列来存储日期:
The trigger should simply read:
There is no requirement to issue another update of the same row (and as you have found, you cannot).
It is more usual to use DATE columns to store dates: