PLSQL Autonomous Transaction

Autonomous Transaction

Autonomous Transactions:-Autonomous transaction is a independent Transaction that is called by another transaction.
                         Autonomous Transactions is a way by which we can call function or procedure as a complete transaction without affecting main transaction (Calling Environment).

Note:-When an autonomous transaction is called, the main transaction (calling transaction) is being temporarily suspended. The autonomous transaction must commit or roll back before it returns
      to calling transaction.

Declaration :- PRAGMA AUTONOMOUS_TRANSACTION;

Example:-
Declare
PRAGMA AUTONOMOUS_TRANSACTION;
begin
update emp set sal=sal+2000 where deptno=10;
commit;
end;
/
update emp set sal=sal+5000 where deptno=20;

rollback;

Note:-When rollback executed here then only last update statement will rollbacked so here executed procedure is working as a autonomous transaction.

No comments:

Post a Comment