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

08-07-07, 08:58
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 11
|
|
|
Nested stored procedures in DB2
|
|
Hi,
I have 2 stored procedures A and B. A makes a call to B and B returns a cursor to A. Stored Procedure B executes fine individually. However, when I execute A, I get the following error:
SQLState = 07003
SQLCode = -518
Code snippet for stored procedure B:
DECLARE SampleCursor CURSOR WITH RETURN TO CALLER FOR
SELECT *
FROM TABLE
FETCH FIRST 5 ROWS ONLY;
OPEN SampleCursor
Code snippet for stored procedure A:
DECLARE LOC1 RESULT_SET_LOCATOR VARYING;
CALL B(OUT_SQLCODE, OUT_SQLSTATE, OUT_MESSAGE);
ASSOCIATE RESULT SET LOCATOR (:LOC1) WITH PROCEDURE B;
ALLOCATE CSR1 CURSOR FOR RESULT SET :LOC1;
EXECUTE CSR1 USING LOC1;
Can anyone please help me with this?
|
|

08-07-07, 10:49
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
I think cursors are supposed to be OPEN'ed, not EXECUTE'd...
|
|

08-07-07, 11:48
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
|
|
EXECUTE is for dynamic SQL, which you have to PREPARE first. The explanation for message SQL0518 tells you that.
But as n_i said, you want to use OPEN instead.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|

08-08-07, 00:49
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 11
|
|
I had tried to OPEN the cursor. However, I got the following error:
THE OPEN STATEMENT FOR CURSOR "CSR1" IS INVALID BECAUSE THE CURSOR WAS DEFINED BY AN ALLOCATE CURSOR STATEMENT
Any idea about how this can be done?
|
|

08-08-07, 07:10
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
Well, since the cursor was in fact opened by the nested procedure, you should be able to fetch from it after the ALLOCATE statement.
|
|

08-08-07, 08:55
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 11
|
|
Hmm. I just need to return the cursor from the calling stored procedure. I don't want to fetch values from the cursor into local variables by looping. Can you please suggest how this can be done?
|
|

08-08-07, 10:04
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
Quote:
|
Originally Posted by Yogesh Pandit
Hmm. I just need to return the cursor from the calling stored procedure.
|
Then you should have declared it WITH RETURN TO CLIENT.
|
|

08-09-07, 05:42
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 11
|
|
I tried using "WITH RETURN TO CLIENT" in the cursor definition. However, I am getting a compilation error:
ILLEGAL SYMBOL "CLIENT". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: CALLER
I am using DB2 V8. Has it got anything to do with this error?
|
|

08-10-07, 02:41
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
I guess you are on DB2 for z/OS? Because DB2 LUW definitively supports WITH RETURN TO CLIENT, whereas DB2 z/OS does not yet allow this syntax.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|

08-13-07, 05:24
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 11
|
|
Yes Stolze, I am using DB2 on z/OS. I tried looking for pointers on the net. But, unfortunately could not get any. Can you please help me with this?
|
|

08-20-07, 07:40
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 11
|
|
Hey Stolze, can you please help me with this? I am trying to figure out a way to call my nested stored procedure.
|
|

08-21-07, 06:43
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
The call is not the problem. Returning result sets to the client (instead to the caller) is. As far as I have found, this is not yet supported.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|

08-21-07, 23:58
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 11
|
|
We found a workaround for this.Get the ResultSet in caller SP, loop through it to read the data and make entries in a temporary table. Then have another cursor which reads this temporary table and sends ResultSet out.
|
|

08-22-07, 04:41
|
|
Registered User
|
|
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
|
|
Yes, that will work, of course.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|