The procedure must act as an independent transaction irrespective of its parent transaction
Autonomous Transaction provides a way to treat it as a separate transaction and save/discard that transaction without affecting the primary session transaction. Suppose some Procedure/package calls another procedure/function/package then you want to save the data irrespective of its parent procedure transaction whether it rollback or commit. You only want to commit in that case you have to use Autonomous transaction to treat as a separate transaction.
Syntax for using Autonomous Transaction:
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
.
BEGIN
<executin_part>
[COMMIT|ROLLBACK]
END;
Note:
- The use of commit / Rollback is a must after the autonomous transaction.
- PRAGMA AUTONOMOUS_TRANSATION should be given in the declarative section of that block to start an independent transition.
Example:
create or replace procedure update_salary
is
pragma autonomous_transaction;
begin
update test.emp set salary = salary +100 where employee_id = 100;
commit;
end;
/
Error handle similar case: https://smarttechways.com/2020/04/02/ora-06519-active-autonomous-transaction-detected-and-rolled-back/