ORA-04091 - How can I alter a table that a trigger fires on?

丶灬走出姿态 提交于 2019-12-24 16:27:39

问题


So I have table foo and I would like to delete other foo rows when trigger t_foo fires:

CREATE OR REPLACE TRIGGER "t_foo" AFTER INSERT OR DELETE OR UPDATE ON foo

/*delete some other records from foo that are not :NEW.* or :OLD.* \*

How would I go about doing this without getting a ORA-04091: table name is mutating, trigger/function may not see it. Is this even possible?


回答1:


Why not do this in a stored procedure, where you can wrap the insert and deletes in a transaction, and can clearly document this side-effect behavior?




回答2:


See Tom Kyte's definitive article on this topic.




回答3:


This basically implies you have interdependent rows in your table, possibly a hierarchical structure with a self-reference from a column to the primary key. Did you think about ON DELETE CASCADE?



来源:https://stackoverflow.com/questions/4367089/ora-04091-how-can-i-alter-a-table-that-a-trigger-fires-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!