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: .

Copy File to/from Remote Server using PL/SQL Coffee Rumba, “Kopi Dangdut” in Japan Version

12 Comments Add your own

  • 1. ferland  |  10 April 2007 at 2:33 pm

    hmm…
    ….hmm……
    …….????….
    Oooooo :D

    Reply
  • 2. Firas  |  10 November 2007 at 5:20 pm

    you should be a teatcher, really thanks

    Reply
  • 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 .

    Reply
  • 4. firmanhm  |  31 January 2008 at 9:50 pm

    so sorry, too late.. you may contact me via firmanhm@yahoo.com

    thx

    Reply
  • 5. santosh  |  13 April 2008 at 1:58 am

    Thanks a ton!!

    Reply
  • 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

    Reply
  • 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

    Reply
  • 8. raina  |  28 December 2009 at 1:08 pm

    please define a line no.9.

    why to use it

    Reply
  • 9. zo  |  19 May 2011 at 12:37 am

    someone to know haw can escape/catch locked records in PL\SQL stored procedure

    Reply
  • 10. bharathi  |  29 October 2011 at 6:35 pm

    bharathi

    Reply
  • 11. bharathi  |  29 October 2011 at 6:36 pm

    really too good example

    Reply
  • 12. YOGESH  |  20 December 2011 at 1:34 pm

    Have you tested both the block?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


 

March 2007
M T W T F S S
« Dec   Apr »
 1234
567891011
12131415161718
19202122232425
262728293031  

My Certification

Oracle Form 10g Certification RDBMS Concepts Certification Oracle PL/SQL Fundamental Certification

Advertise

Web Store belidong.com

Follow

Get every new post delivered to your Inbox.