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 > call sp from inside another sp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-10-08, 04:14
chesl73 chesl73 is offline
Registered User
 
Join Date: Oct 2008
Posts: 19
call sp from inside another sp

All,

I have two stored procs that both return resultsets and i would like to have a main stored proc and use this to call one or the other of my two stored procs.
I would then like to return the resultset of the one I call back to the client.

I have the following but it doesn't work, can't find much reference to it. Can anyone help?

CREATE PROCEDURE MAINONE(IN MYVAR VARCHAR(50))
RESULT SETS 1
MODIFIES SQL DATA
NOT DETERMINISTIC
LANGUAGE SQL

BEGIN

DECLARE C1 CURSOR WITH RETURN TO CALLER FOR

IF MYVAR='1' THEN
CALL PROC_ONE;
ELSE
CALL PROC_TWO;
END IF;

-- REALLY NOT SURE ABOUT NUMBER OF CURSORS TO OPEN OR TO RETURN ----TO WHAT? NOT SURE OF GENERAL STRUCTURE?

BEGIN
DECLARE C2 CURSOR WITH RETURN TO CLIENT FOR;
C2 = C1;
OPEN C2;
END;

END
@
Reply With Quote
  #2 (permalink)  
Old 10-13-08, 07:36
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
That's simple: in the nested procedure, you have to say WITH RETURN TO CLIENT and open the cursor there. The outer procedure doesn't care about cursors at all.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 10-13-08, 19:45
chesl73 chesl73 is offline
Registered User
 
Join Date: Oct 2008
Posts: 19
Do you mean as below? If so, this doesn't work. I get an error saying 'An unexpected token "CALL" was found following "RETURN TO CLIENT FOR"

BEGIN

IF MYVAR='1' THEN
DECLARE C1 CURSOR WITH RETURN TO CLIENT FOR
CALL PROC_ONE;
open C1;
ELSE
DECLARE C2 CURSOR WITH RETURN TO CLIENT FOR
CALL PROC_TWO;
open C2;
END IF;



END
Reply With Quote
  #4 (permalink)  
Old 10-14-08, 06:55
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
The 1st cursor is declared inside PROC_ONE and the 2nd cursor inside PROC_TWO. At those declarations, you have to say WITH RETURN TO CLIENT. You don't have to care about those cursors in your main procedure, i.e.
Code:
BEGIN
   IF MYVAR='1' THEN
      CALL PROC_ONE;
   ELSE
      CALL PROC_TWO;
   END IF;
END
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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