gpt4 book ai didi

sql - 如何在触发器调用的过程中使用 COMMIT

转载 作者:行者123 更新时间:2023-12-04 23:42:59 24 4
gpt4 key购买 nike

我有下面的触发器(mytrg),它调用一个过程(myproc),如果在 table1 中有任何插入,它将更新 table2。在表2中更新数据后,我在过程中有“COMMIT”语句。但是当 table1 中有插入时,我收到以下错误。

Error report:
SQL Error: ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "myschema.myproc", line 63
ORA-06512: at "myschema.mytrg", line 2
ORA-04088: error during execution of trigger 'myschema.mytrg'
04092. 00000 - "cannot %s in a trigger"
*Cause: A trigger attempted to commit or rollback.
*Action: Rewrite the trigger so it does not commit or rollback.

**Trigger:**
create or replace
trigger mytrg
after insert on table1
for each row
begin
myschema.myproc(:new.ID, :new.NAME, :new.TYPE_CODE, :new.LANGUAGE);
end;

需要知道如何提交更新。

谢谢

最佳答案

触发器中不能有 COMMIT。一旦提交到 table1 的 INSERT,您的 UPDATE 将被提交。

但是要实现您想要的,您可以使用自治事务。例如,

CREATE OR REPLACE TRIGGER mytrg
AFTER INSERT ON table1 FOR EACH ROW

DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
myschema.myproc(:new.ID, :new.NAME, :new.TYPE_CODE, :new.LANGUAGE);
COMMIT;
END;

关于sql - 如何在触发器调用的过程中使用 COMMIT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23295294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com