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 rollback only single stored procedure action?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-24-10, 02:24
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
How to rollback only single stored procedure action?

Hi,
I would like to create a stored procedure which runs two stored procedures one after another. If first stored procedure runs successful and second fails than I do NOT want to rollback first stored procedure SQLs.

I have written bellow simple sample. But if I execute admin.sp_run and force application in the time second stored procedure is executing (admin.sp2) then SQL from first stored procedure (admin.sp1) is also rollbacked.

Is there any way I can write a admin.sp_run procedure in such a way that if admin.sp2 procedure fails it does not rollback admin.sp1 actions.

Code:
CREATE TABLE ADMIN.TAB (COL1 INT)@

CREATE PROCEDURE ADMIN.SP1
  LANGUAGE SQL
  BEGIN
    INSERT INTO ADMIN.TAB VALUES (1);
  END@

CREATE PROCEDURE ADMIN.SP2
  LANGUAGE SQL
  BEGIN
    UPDATE ADMIN.TAB SET COL1 = 2;
  END@

CREATE PROCEDURE ADMIN.SP_RUN
  LANGUAGE SQL
  BEGIN
     CALL ADMIN.SP1 ();
     CALL ADMIN.SP2 ();
  END
@

CALL ADMIN.SP_RUN()
Thanks
Reply With Quote
  #2 (permalink)  
Old 12-24-10, 03:24
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
I have found out. Commit statement must be inserted into first procedure like:
Code:
CREATE PROCEDURE ADMIN.SP1
  LANGUAGE SQL
  BEGIN
    INSERT INTO ADMIN.TAB VALUES (1);
    COMMIT;
  END@
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