ORACLE 回滚和触发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1104737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORACLE Rollback and Trigger
提问by moejoe11
Does the after Update trigger will kick off if there is a rollback?
如果有回滚,更新后触发器是否会启动?
Scenario: Lets say we update a table A and the trigger on table A kicks off and updates another table B with the details. If there is a rollback issued on table A due to some processing error, will the trigger cause the table B to rollback the change?
场景:假设我们更新表 A,表 A 上的触发器启动并使用详细信息更新另一个表 B。如果由于某些处理错误在表 A 上发出了回滚,触发器是否会导致表 B 回滚更改?
回答by Quassnoi
Yes, it will.
是的,它会。
Triggers work in scope of the DML
statement's transaction (either started by you explicitly or by the DML
statement itself implicitly)
触发器在DML
语句的事务范围内工作(由您显式启动或由DML
语句本身隐式启动)
When this transaction is rolled back, all changes made by the triggers are also rolled back.
当此事务回滚时,触发器所做的所有更改也将回滚。
However, if you put
但是,如果你把
PRAGMA autonomous_transaction
into the trigger definition, the trigger will start its own transaction which you should commit before the trigger completes.
进入触发器定义,触发器将启动它自己的事务,您应该在触发器完成之前提交该事务。
回答by jva
Just a note - if you define AFTER UPDATE statement level trigger (without FOR EACH ROW clause) it will not fire if DML statement on the table fails and is rolled back.
请注意 - 如果您定义 AFTER UPDATE 语句级触发器(没有 FOR EACH ROW 子句),如果表上的 DML 语句失败并回滚,它将不会触发。