oracle中的复合触发器

发布于 2024-08-17 00:48:14 字数 389 浏览 5 评论 0原文

我有一个复合触发器,在 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;

更新只是一个简单的更新,看看是否有效。我希望它在 THEOTHERTABLE 上触发触发器,但只有在触发器不是复合触发器时才会触发。

这是 Oracle 复合触发器的问题还是只是我不理解的功能?

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:

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.

Is this a problem with Oracle compound triggers or just a feature which I am not understanding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长安忆 2024-08-24 00:48:14

我尝试重新创建您的场景,它似乎对我来说效果很好。所以我认为你应该再次审视你的实施。寻找您所编码的内容与此处接下来的内容之间的差异,也许这就是答案所在。

这是我的触发器

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>

...这是测试数据......

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> 

这就是我在第一个表上发出更新时发生的情况...

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>

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>
待天淡蓝洁白时 2024-08-24 00:48:14

如果您在编译触发器后执行此操作,它会起作用,但如果您再次尝试,即使使用其他数据,它也不会更新 THEOTHERTABLE

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

甜尕妞 2024-08-24 00:48:14

我认为它不应该工作...如果您为 THEOTHERTABLE 创建一个过程并从此触发器调用该过程,那就更好了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文