If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to use PRAGMA AUTONOMOUS_TRANSACTION in DB2 ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-12-05, 13:33
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
Question How to use PRAGMA AUTONOMOUS_TRANSACTION in DB2 ?

Hi, all

I have a procedure in oracle that contains PRAGMA AUTONOMOUS_TRANSACTION, someone knows what is the statement in DB2 that makes the same think.

Thanks a lot.

Last edited by Alairj; 01-12-05 at 13:48.
Reply With Quote
  #2 (permalink)  
Old 01-12-05, 13:54
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
There's no such thing in DB2.
Reply With Quote
  #3 (permalink)  
Old 01-12-05, 14:50
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
But that isn't nothing in DB2, that can i do to make a commit or a rollback, only in the processes that are included in my procedure or routine?
Reply With Quote
  #4 (permalink)  
Old 01-12-05, 16:18
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
There's always a workaround; however it's difficult to give adivce not knowing your reasons.

AUTONOMOUS_TRANSACTION feature in Oracle is often used to overcome that "mutating table" problem, which doesn't exist in DB2 - therefore you may not need autonomous transactions at all when developing for DB2.
Reply With Quote
  #5 (permalink)  
Old 01-13-05, 08:10
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
In my case i want AUTONOMOUS_TRANSACTION to do something like that:

I have a procedure that executs a insert and i want to do a COMMIT only in this insert, if i execute before another insert this will not be commited, only the insert that contains the AUTONOMOUS_TRANSACTION, i don't know if you understand, i don't speek english very well.

Thanks a lot.
Reply With Quote
  #6 (permalink)  
Old 01-13-05, 09:49
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I haven't tried it myself by you could see if the following would work for you:
Code:
-- this insert lives on
INSERT ... INTO ...;
SAVEPOINT SP1;
-- this insert is conditional
INSERT ...
IF something is wrong THEN
   ROLLBACK TO SAVEPOINT SP1;
END IF;
COMMIT;
Reply With Quote
  #7 (permalink)  
Old 01-13-05, 10:30
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
But in this case the db2 will commit the first insert, the second insert or both?
Reply With Quote
  #8 (permalink)  
Old 01-13-05, 11:14
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
I think that if you roll back to the savepoint in the above example only the first insert will be committed; otherwise both will be committed.
Reply With Quote
  #9 (permalink)  
Old 01-13-05, 11:34
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
In my case i want to commit only the second insert, the first i'll not commit, with a savepoint can i do that?
Reply With Quote
  #10 (permalink)  
Old 01-13-05, 11:45
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
If you commit the second insert regardless of the success of the first one you might as well change their order; then the second becomes the first...
Reply With Quote
  #11 (permalink)  
Old 01-13-05, 12:01
Alairj Alairj is offline
Registered User
 
Join Date: Nov 2004
Location: São Paulo, Brazil
Posts: 32
I know this, but i need the first insert to executes the second, i can't change the order of them, in oracle do that is simple, as the same as i can isolate a statement ( in this case a insert ) i only want to validate ( commit ) the rows inserted or updated in this statement, and the others statements that i execute after or before that will not be commited.

Thanks a lot for your atention.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On