create or replace trigger tig_tt
after update on tt
for each row
declare
rstr varchar2(1024);
PRAGMA AUTONOMOUS_TRANSACTION;
begin
INSERT INTO TT
(ID, text)
values
(100, 'def_失败:' || tO_CHAR(sysdate, 'yyyy-mm-dd hh24:mi:ss'));
exception
when others then
rstr := '执行触发器失败 :' || sqlcode || ':' || sqlerrm;
dbms_output.put_line(rstr);
insert into tt (id, text) values (200, rstr);
end tig_tt;
SQL> update tt set id=3;
执行触发器失败 :-6519:ORA-06519: 检测到活动的自治事务处理, 已经回退
update tt set id=3
ORA-04091: 表 LANDUSER.TT 发生了变化, 触发器/函数不能读它
ORA-06512: 在 "LANDUSER.TIG_TT", line 14
ORA-06519: 检测到活动的自治事务处理, 已经回退
ORA-04088: 触发器 'LANDUSER.TIG_TT' 执行过程中出错
问题:自治事务处理没有提交commit
修改如下:
create or replace trigger tig_tt
after update on tt
for each row
declare
rstr varchar2(1024);
PRAGMA AUTONOMOUS_TRANSACTION;
begin
INSERT INTO TT
(ID, text)
values
(100, 'def_失败:' || tO_CHAR(sysdate, 'yyyy-mm-dd hh24:mi:ss'));
commit;
exception
when others then
rstr := '执行触发器失败 :' || sqlcode || ':' || sqlerrm;
dbms_output.put_line(rstr);
insert into tt (id, text) values (200, rstr);
commit;
end tig_tt;
就没有错误了