ORA-04091 - 如何更改触发器触发的表?
所以我有表 foo
并且我想在触发器 t_foo
触发时删除其他 foo
行:
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.* \*
我将如何在没有获得ORA-04091:
表名正在发生变化,触发器/函数可能看不到它。这可能吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不在存储过程中执行此操作,您可以在存储过程中将插入和删除包装在事务中,并且可以清楚地记录这种副作用行为?
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?
请参阅 Tom Kyte 关于此主题的权威文章。
See Tom Kyte's definitive article on this topic.
这基本上意味着表中存在相互依赖的行,可能是具有从列到主键的自引用的分层结构。您是否考虑过
ON DELETE CASCADE
?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
?