oracle 触发错误 ORA-04092 ORA-04088

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2264693/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:00:09  来源:igfitidea点击:

Trigger errors ORA-04092 ORA-04088

sqloracletriggersora-04088

提问by Vijay

I created a trigger as below:

我创建了一个触发器,如下所示:

CREATE OR REPLACE TRIGGER trigger_test
AFTER INSERT ON trigger_1
FOR EACH ROW
DECLARE
t_identifier VARCHAR2(10);
t_name VARCHAR2(20);
BEGIN
t_identifier := (:NEW.IDENTIFIER);
t_name := (:NEW.NAME);
INSERT INTO trigger_2(IDENTIFIER,NAME)VALUES(t_identifier,t_name);
COMMIT;
END;

I am trying to insert a row in trigger_1

我正在尝试在 trigger_1 中插入一行

INSERT INTO trigger_1(IDENTIFIER,NAME)
VALUES('1234567','Vijay');

It is giving me the errors:

它给了我以下错误:

ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "LVSDBO46.TRIGGER_TEST", line 8
ORA-04088: error during execution of trigger 'LVSDBO46.TRIGGER_TEST'

Could nybody please help?

有人可以帮忙吗?

回答by Nils Weinander

Just remove

只需删除

COMMIT;

from the trigger code. Trigger execute in an ongoing transaction, so you cannot do a separate commit. When the transaction is commited, your insert in trigger_2 will also be commited.

从触发代码。触发器在正在进行的事务中执行,因此您不能进行单独的提交。提交事务后,您在 trigger_2 中的插入也将被提交。

回答by Khb

Might I suggest shortening it a bit.

我是否建议将其缩短一点。

CREATE OR REPLACE TRIGGER trigger_test
  AFTER INSERT ON trigger_1
  FOR EACH ROW
  BEGIN
    INSERT INTO trigger_2 (IDENTIFIER,NAME) VALUES (:NEW.IDENTIFIER,:NEW.NAME);
  END;

回答by Erich Kitzmueller

In case you really really need to commit (chances are you don't have to, but just in case...) you can create a procedure with the AUTONOMOUS_TRANSACTION PRAGMA.

如果您真的需要提交(您可能不必提交,但以防万一……)您可以使用 AUTONOMOUS_TRANSACTION PRAGMA 创建一个过程。