我有桌子
messages (
id number,
mess varchar2(4000),
short_mess(100) )
我想创建类似的东西的触发器:
INSERT into messages ( id, message ) values ( some_id, some_message)
然后在表格messages
中,我希望( some_id, some_message, some_message_shortcut)
我的触发器如下所示:
create or replace trigger "MESSAGES_T1"
AFTER
insert on "MESSAGES"
for each row
begin
UPDATE MESSAGES set "short_mess" = 'aaa'
where id = :new.id;
end;
但是当我尝试进入新行时我会收到错误
ORA-04091: table FIRSTAPP.MESSAGES is mutating, trigger/function may not see it ORA-06512: at "FIRSTAPP.MESSAGES", line 2 ORA-04088: error during execution of trigger 'FIRSTAPP.MESSAGES'
我该怎么做? ('aaa'
仅用于测试目的)
提前谢谢。
答案 0 :(得分:1)
不要更新,只需指定新值即可。但是你需要一个BEFORE
触发器才能工作,你不能修改AFTER
触发器中的新行:
create or replace trigger "MESSAGES_T1"
BEFORE insert on "MESSAGES"
for each row
begin
:new.short_mess := 'aaa';
end;
/