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 _ failed: '| to_char (sysdate, 'yyyy-mm-dd hh24: MI: ss '));
Exception
When others then
Rstr: = 'trigger execution failed: '| sqlcode |': '| sqlerrm;
Dbms_output.put_line (rstr );
Insert into TT (ID, text) values (200, rstr );
End tig_tt;
SQL> update TT Set ID = 3;
Trigger execution failed:-6519: ORA-06519: autonomous transaction processing detected for activity, rolled back
Update TT Set ID = 3
ORA-04091: The table landuser. tt has changed and trigger/function cannot read it
ORA-06512: In "landuser. tig_tt", line 14
ORA-06519: detected active autonomous transaction processing, rolled back
ORA-04088: An error occurred while executing the trigger 'landuser. tig_tt'
Problem: No commit is submitted for autonomous transaction processing.
Modify as follows:
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 _ failed: '| to_char (sysdate, 'yyyy-mm-dd hh24: MI: ss '));
Commit;
Exception
When others then
Rstr: = 'trigger execution failed: '| sqlcode |': '| sqlerrm;
Dbms_output.put_line (rstr );
Insert into TT (ID, text) values (200, rstr );
Commit;
End tig_tt;
No errors