关于触发顺序
桌子上有两个触发器。当表中的每一行有插入或更新时,就会执行一个触发器。当表中的每一行有更新时,将执行第二个触发器。在ORACLE 10G中,当表中的一行有更新语句时,哪个触发器首先执行。 oracle中触发器有执行顺序吗?如果可以我该如何设置?
Have two triggers on a table. One trigger is executed when there is a insert or update for each row in the table. Second trigger is executed when there is a update for each row in the table. Which trigger gets executed first in ORACLE 10G when there is a update statement on a row in the table. Is there any order of execution for triggers in oracle? If so how can i set it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
触发器触发的顺序是任意的,您无法在 10g 中控制。我相信,从技术上讲,它是按照触发器创建的顺序进行的,但这肯定不是您想要指望的。
在11g中,您可以控制触发器的触发顺序。然而,用一个调用两个存储过程的触发器替换这两个触发器几乎总是更好。所以,比起
你会得到更好的服务,比如
The order in which the triggers will fire is arbitrary and not something that you can control in 10g. I believe, technically, it goes in the order that the triggers happened to be created but that's certainly not something that you'd want to count on.
In 11g, you can control the firing order of triggers. However you are almost always better off replacing the two triggers with one trigger that calls two stored procedures. So rather than
you would be much better served with something like
对于 11g 之前的版本,否,顺序未指定。来自 10g 第 2 版文档 :
For versions before 11g, no, the order is unspecified. From 10g Release 2 docs:
在 10g 中,除了正常的 before 语句、before row、after row、after statements 顺序之外,不能依赖任何触发触发的顺序。在 11g 中,新的 FOLLOWS 子句添加到 CREATE TRIGGER 语句。
No order to trigger firing can be relied upon in 10g beyond the normal before statement, before row, after row, after statement order. In 11g a new FOLLOWS clause was added to the CREATE TRIGGER statement.
在 Oracle 10g 中,我们不控制在同一时间创建的触发器。它是随机执行的。所以我们不能说哪个触发器首先被触发。为了解决这个问题,Oracle 11g 引入了
FOLLOWS CLAUSE
。使用它我们可以控制执行顺序。In Oracle 10g we do not control the triggers that are created on same timing. It is executed randomly. So we cannot say which trigger is fired first. To overcome this problem, Oracle 11g introduced
FOLLOWS CLAUSE
. Using this we can control the execution order.