oracle oracle中的复合触发器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2006127/
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
Compound triggers in oracle
提问by Joao
I have a compound trigger and in the after statement I have an update to other table that has also a compound trigger, like in the code below:
我有一个复合触发器,在 after 语句中,我对其他也有复合触发器的表进行了更新,如下面的代码所示:
create or replace
trigger TRIGGER
for insert or update on TABLE
COMPOUND trigger
after STATEMENT is
begin
update THEOTHERTABLE set VALUE = VALUE + 1 where COD = 1;
end after STATEMENT;
end;
The update is just a simple one to see if works. I want it to fire the trigger on THEOTHERTABLE, but it only fires if the trigger is not compound.
更新只是一个简单的更新,看看是否有效。我希望它在 THEOTHERTABLE 上触发触发器,但只有在触发器不是复合的情况下才会触发。
Is this a problem with Oracle compound triggers or just a feature which I am not understanding?
这是 Oracle 复合触发器的问题还是我不理解的功能?
回答by APC
I have attempted to re-create your scenario, and it appears to work fine for me. So I think you should look again at your implementation. Look for the differences between what you have coded and what follows here, and perhaps that is where the answer lies.
我试图重新创建您的场景,它对我来说似乎工作正常。所以我认为你应该再看看你的实现。寻找您编码的内容与此处后面的内容之间的差异,也许这就是答案所在。
Here are my triggers
这是我的触发器
SQL> create or replace
2 trigger t1_compound
3 for insert or update on t1
4 compound trigger
5
6 after statement is
7 begin
8 update t2 set t1_id = nvl(t1_id,0) + 1 where cod = 12;
9 end after statement;
10 end;
11 /
Trigger created.
SQL>
SQL> create or replace
2 trigger t2_compound
3 for insert or update on t2
4 compound trigger
5
6 after statement is
7 begin
8 update t3 set t2_id = nvl(t2_id,0) + 1 where cod = 12;
9 end after statement;
10 end;
11 /
Trigger created.
SQL>
... here is the test data ...
...这是测试数据...
SQL> select id, cod from t1
2 /
ID COD
---------- ----------
1 12
SQL> select id, cod, t1_id from t2
2 /
ID COD T1_ID
---------- ---------- ----------
11 12
SQL> select id, cod, t2_id from t3
2 /
ID COD T2_ID
---------- ---------- ----------
111 12
SQL>
... and this is what happens when I issue an update on the first table ...
...这就是当我在第一个表上发布更新时发生的情况......
SQL> update t1 set dt = sysdate
2 where id = 1
3 /
1 row updated.
SQL> select id, cod, t1_id from t2
2 /
ID COD T1_ID
---------- ---------- ----------
11 12 1
SQL> select id, cod, t2_id from t3
2 /
ID COD T2_ID
---------- ---------- ----------
111 12 1
SQL>
回答by jcsmata
It works if you do it after compiling the trigger but if you try it again, even with other data, it won't update THEOTHERTABLE
如果您在编译触发器后执行它,它会起作用,但是如果您再次尝试,即使使用其他数据,它也不会更新 THEOTHERTABLE
回答by GxG
i don't think it should work...it would be better if you would create a procedure for THEOTHERTABLE and call that procedure from this trigger.
我不认为它应该工作......如果你为 THEOTHERTABLE 创建一个过程并从这个触发器调用该过程会更好。