ORA-04091:表名称正在变异 [英] ORA-04091: table name is mutating
问题描述
将数据插入表A时出现ORA-04091错误.表A记录引用了同一表1:N中的其他记录. 父记录的fk_id = null,子记录的fk不为null.
I get ORA-04091 Error while inserting data into table A. Table A records are refferencing other records in the same table 1:N. Father records have fk_id = null and child records have fk not null.
create or replace trigger TRBI_A
BEFORE INSERT ON A
for each row
BEGIN
IF :new.fk_id IS NOT NULL then
UPDATE A SET actualTS = CURRENT_TIMESTAMP WHERE id = :new.fk_id;
END IF;
END;
ORA-04091:表名称正在更改,触发器/函数可能看不到
ORA-04091: table name is mutating, trigger/function may not see it
该问题可能是由触发器引起的,该触发器试图修改或查询触发该触发器的语句当前正在修改的表. 有人知道如何修改触发器以使其正确吗?
The problem could is probably caused by trigger which tried to modify or query a table that is currently being modified by the statement that fired the trigger. Does anyone know how to modify the trigger to have it correct?
推荐答案
您知道问题出在哪里,因此,只需稍微阅读一下代码即可:更新与触发器相同的表.
You know what the problem is, so just read your code a little: you update the same table you are putting the trigger on.
我想在您的情况下,您只需要放入:NEW.actualTS:=current_timestamp
,而不使用update语句即可.
I guess in your case you just need to put :NEW.actualTS:=current_timestamp
, without using the update statement.
这篇关于ORA-04091:表名称正在变异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!