PRAGMA AUTONOMOUS_TRANSACTION in PL/SQL
30 March 2007 at 11:31 am 12 comments
To understand this, do the pl/sql below
SQL> declare
2 procedure insert_to_table_a is
3 begin
4 insert into table_a values (‘A’);
5 commit;
6 end;
7 begin
8 insert into table_b values(‘B’);
9 insert_to_table_a;
10 rollback;
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> select * from table_a;
CO
–
A
SQL> select * from table_b;
CO
–
B
COMMIT at line no 5 , commits the transaction at line-no 4 and line-no 8.
Let us see the following example using PRAGMA AUTONOMOUS_TRANSACTION.
SQL> declare
2 procedure insert_to_table_a is PRAGMA AUTONOMOUS_TRANSACTION;
3 begin
4 insert into table_a values (‘A’);
5 commit;
6 end;
7 begin
8 insert into table_b values(‘B’);
9 insert_to_table_a;
10 rollback;
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> select * from table_a;
CO
–
A
SQL> select * from table_b;
no rows selected
So, with the PRAGA AUTONOMOUS_TRANSACTION, the transaction state maintained independently. Commit/Rollback of nested transaction will no effect the other transaction
Entry filed under: Oracle. Tags: .




1.
ferland | 10 April 2007 at 2:33 pm
hmm…
….hmm……
…….????….
Oooooo
2.
Firas | 10 November 2007 at 5:20 pm
you should be a teatcher, really thanks
3.
shalini | 25 January 2008 at 2:33 pm
hi,
gr8 job!!!!!!!!!!!!
can u pls tell me how can i contact u for further more queries regarding SQL or PL/SQL .
4.
firmanhm | 31 January 2008 at 9:50 pm
so sorry, too late.. you may contact me via firmanhm@yahoo.com
thx
5.
santosh | 13 April 2008 at 1:58 am
Thanks a ton!!
6.
Andy Cheong | 15 April 2008 at 5:48 pm
is the pragma can be used in Oracle form?
I have tried to put the pragma in one of the procedure in the package in Oracle form. However, it gives me compilation error: Error 127
pragma AUTONOMOUS_TRANSACTION is not a supported pragma…
Any one can help?
Thanks
7.
firmanhm | 14 May 2008 at 1:53 pm
You can move the PL/SQL in your form to database as package, procedure or function.
Then call it in your form.
Please correct me if i wrong.
Thanks
8.
raina | 28 December 2009 at 1:08 pm
please define a line no.9.
why to use it
9.
zo | 19 May 2011 at 12:37 am
someone to know haw can escape/catch locked records in PL\SQL stored procedure
10.
bharathi | 29 October 2011 at 6:35 pm
bharathi
11.
bharathi | 29 October 2011 at 6:36 pm
really too good example
12.
YOGESH | 20 December 2011 at 1:34 pm
Have you tested both the block?