变异,触发器/函数可能看不到它 - 触发器执行期间出错

发布于 2024-09-04 21:55:06 字数 853 浏览 2 评论 0原文

CREATE OR REPLACE TRIGGER UPDATE_TEST_280510
AFTER insert on TEST_TRNCOMPVISIT
declare
V_TRNCOMPNO NUMBER(10);

CURSOR C1 IS SELECT B.COMPNO FROM TEST_TRNCOMPVISIT A, TEST_TRNCOMPMST B, 
                                  TEST_MEMMAST C
WHERE A.COMPNO=B.COMPNO 
AND B.TRNMEMID=C.MEMID 
AND C.MEMOS>=1000;

begin
open c1;
fetch c1 into V_TRNCOMPNO;


UPDATE TEST_TRNCOMPMST SET COMPSTATUS='P',
       remark='comp is pending due to O/S>1000'
WHERE COMPNO=V_TRNCOMPNO AND COMPSTATUS='C';
CLOSE C1;

end;

我已经制作了此触发器,并且在表中插入行时 - TEST_TRNCOMPVISIT 它给出了以下错误 -

发生了以下错误:

ORA-04091: 表 TEST.TEST_TRNCOMPVISIT 正在发生变化,触发器/函数可能看不到它
ORA-06512: 在“TEST.UPDATE_TEST_280510”,第 4 行
ORA-06512: 在“TEST.UPDATE_TEST_280510”,第 10 行
ORA-04088:执行触发器“TEST.UPDATE_TEST_280510”期间出错

CREATE OR REPLACE TRIGGER UPDATE_TEST_280510
AFTER insert on TEST_TRNCOMPVISIT
declare
V_TRNCOMPNO NUMBER(10);

CURSOR C1 IS SELECT B.COMPNO FROM TEST_TRNCOMPVISIT A, TEST_TRNCOMPMST B, 
                                  TEST_MEMMAST C
WHERE A.COMPNO=B.COMPNO 
AND B.TRNMEMID=C.MEMID 
AND C.MEMOS>=1000;

begin
open c1;
fetch c1 into V_TRNCOMPNO;


UPDATE TEST_TRNCOMPMST SET COMPSTATUS='P',
       remark='comp is pending due to O/S>1000'
WHERE COMPNO=V_TRNCOMPNO AND COMPSTATUS='C';
CLOSE C1;

end;

I have made this trigger and while insert the row in table- TEST_TRNCOMPVISIT it gives following error-

The following error has occurred:

ORA-04091: table TEST.TEST_TRNCOMPVISIT is mutating, trigger/function may not see it
ORA-06512: at "TEST.UPDATE_TEST_280510", line 4
ORA-06512: at "TEST.UPDATE_TEST_280510", line 10
ORA-04088: error during execution of trigger 'TEST.UPDATE_TEST_280510'

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

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

发布评论

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

评论(2

巷雨优美回忆 2024-09-11 21:55:07

当定义为 FOR EACH ROW 的触发器尝试访问为其触发的表时,会引发“表正在发生变化”异常。 Tom Kyte 在此处编写了有关此异常的原因和解决方案的精彩指南

在您发布的示例中,您没有 FOR EACH ROW,因此我不希望引发异常。通常,只有在需要访问每一行的 :OLD 或 :NEW 值(但您不需要)的情况下才需要使用 FOR EACH ROW 触发器。

The "table is mutating" exception is raised when a trigger that is defined as FOR EACH ROW tries to access the table that is was fired for. Tom Kyte has written a great guide to the causes and resolution of this exception here.

In your posted example you do not have FOR EACH ROW and so I would not expect the exception to be raised. Usually one only needs to use FOR EACH ROW triggers in cases where it is necessary to access the :OLD or :NEW values of each row, which you are not.

痴情换悲伤 2024-09-11 21:55:07

这是你唯一的触发点吗?
您的触发器更新表 TEST_TRNCOMPMST。如果此表上存在访问 TEST_TRNCOMPVISIT 的触发器,您将收到错误消息。

Is this the only trigger you have?
Your trigger updates table TEST_TRNCOMPMST. If there is a trigger on this table that accesses TEST_TRNCOMPVISIT you get the error message.

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