如何在表中完成数据插入后触发触发器

发布于 2024-12-23 08:18:49 字数 273 浏览 3 评论 0原文

我有一个表 A,我正在其中插入数据。然后进行一些计算来更新相同的表A

我想触发一个触发器,它在数据插入完成后(插入和更新之后)调用Procedure A

我该怎么做?

有没有其他方法可以自动执行...或者我必须在表A中完成数据插入后手动运行程序A


更简单地说,我想知道如何在插入几行和提交后触发触发器,即不是针对每一行。

I have a table A into which I am inserting data. Then some calculation is being done updating the same table A.

I want to fire a trigger, which calls a Procedure A after the completion of data insertion ( after insert and update ).

How do I do this?

Is there any other way to do it automatically... Or do I have to run Procedure A manualy after the completion of data insertion in table A.


More simply, I would like to know how to fire a trigger after inserting a few rows and a commit, i.e. not for each row.

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

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

发布评论

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

评论(3

一场春暖 2024-12-30 08:18:49

您可以定义为每行或每条语句触发的触发器(FOR EACH ROW 选项)。

如果我理解正确的话,你想在一堆语句之后触发触发器吗?别以为你可以。即使可以,我也宁愿不做。它们分散了你的程序流程/逻辑,让以后更难理解你的软件是如何工作的。

问候

You can define your trigger to be fired for each row or for each statement (FOR EACH ROW option).

If I understood you right, you would like to fire the trigger after a bunch of statements? Don't think you can. Even if you can, I would rather not do it. They scatter your program flow / logic and make it harder to understand later how your software works.

Regards

獨角戲 2024-12-30 08:18:49

如果我正确理解您的问题,您希望在完成由多个插入/更新语句组成的事务后触发触发器吗?如果是这种情况,我认为您应该考虑在插入/更新操作完成后立即在程序流中调用您的Procedure A

换句话说:只有在为每行或每条语句调用触发器时,触发器才有用。

If I understand your question correctly, you want the trigger to fire after you completed your transaction consisting of several insert/update statements? If that is the case, I think you should consider calling your Procedure A in your program flow right after the insert/update operations are done.

In other words: A trigger would only be useful, if it should be called for each row or for each statement.

西瑶 2024-12-30 08:18:49

在表中添加一列:例如“FINAL_ACTION”。在您预期的最终行动之前,请保持此列不变。然后仅使用此子句触发您的触发器:

REFERENCING NEW AS NEWREC OLD AS OLDREC
FOR EACH ROW
WHEN (NEWREC.FINAL_ACTION <> OLDREC.FINAL_ACTION)
DECLARE
     --YOUR DECLARATIONS
BEGIN
     --DO SOMETHING
END;

Add one column to your table: e.g "FINAL_ACTION". Leave this column untouched untill your anticipated final action. Then have your trigger get fired only with this clause:

REFERENCING NEW AS NEWREC OLD AS OLDREC
FOR EACH ROW
WHEN (NEWREC.FINAL_ACTION <> OLDREC.FINAL_ACTION)
DECLARE
     --YOUR DECLARATIONS
BEGIN
     --DO SOMETHING
END;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文