C.K*_*C.K 3 sql triggers plsql stored-procedures
我有下面的触发器(mytrg)调用一个过程(myproc),如果table1中有任何插入,它将更新table2.在table2中更新数据后,我在程序中有"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;
Run Code Online (Sandbox Code Playgroud)
需要知道如何提交更新.
谢谢
你不能在触发器中有一个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;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15650 次 |
最近记录: |