我有一个更好地解释情况的例子。我有一张桌子A
CREATE TABLE A( ID NUMBER, VAL NVARCHAR2(255) )
我创建了一个触发器,对刚刚插入的行进行更新
CREATE OR REPLACE TRIGGER XXX
AFTER INSERT
ON A
FOR EACH ROW
DECLARE
BEGIN
UPDATE A SET VAL = 'LOL' WHERE ID = :NEW.ID;
END;
当我执行插入
时INSERT INTO A VALUES(1, 'XX')
我得到了
ORA-04091: table name is mutating, trigger/function may not see it
有解决方法吗?
答案 0 :(得分:0)
您不需要更新,只需在BEFORE
触发器中分配新值。
CREATE OR REPLACE TRIGGER XXX
BEFORE INSERT --<< You need a BEFORE trigger for this to work.
ON A
FOR EACH ROW
BEGIN
:new.val := 'LOL';
END;