插入触发器是否需要提交语句 [英] Does an insert trigger need a commit statement

查看:70
本文介绍了插入触发器是否需要提交语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是实际情况的简化;在哪里可以看到表B上缺少的记录.

This is an simplification of actual scenario; where is see missing records on Table B.

说有两个数据库表A;B.

Say there are two db tables A ; B.

在表A上有一个on插入触发器;它可以对表B进行插入(但它没有COMMIT;).如果我们通过JDBC连接器打开数据库连接;并在表A上插入;并提交;触发器的行为是什么?会自动将其提交到表B上的插入语句吗?

There is an on insert trigger on Table A;which do an insert to Table B (but it doesn't have COMMIT;). If we open a db connection through JDBC connector; and do an insert on Table A; and commit it; What is the behavior of Trigger? Will it be automatically committed the insert statement on table B ?

推荐答案

触发器不仅不需要COMMIT,而且您不能放入COMMIT:如果主体的代码中包含COMMIT(或回滚),则触发器不会编译).

Not only do triggers not need a COMMIT you can't put one in: a trigger won't compile if the body's code includes a COMMIT (or a rollback).

这是因为在交易过程中会触发触发.当触发器触发时,当前事务仍未完成.当COMMIT终止事务时,允许它们进入触发器将破坏工作单元.

This is because triggers fire during a transaction. When the trigger fires the current transaction is still not complete. As COMMIT terminates a transaction allowing them in triggers would break the unit of work.

因此,在触发器中执行的更改由发出触发触发器的DML的拥有事务提交(或回滚).

So changes executed in a trigger are committed (or rolled back) by the owning transaction which issued the DML that fired the trigger.

确实,触发器可以在PRAGMA AUTONOMOUS_TRANSACTION下运行,在这种情况下,它们必须具有COMMIT.但这是一个极端的情况,因为在Oracle中很少有嵌套事务的有意义的用途.

It is true that triggers can run under the PRAGMA AUTONOMOUS_TRANSACTION, in which case they must have a COMMIT. But this is an edge case, as there are few meaningful uses of nested transactions in Oracle.

这篇关于插入触发器是否需要提交语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆