> >> Wrap the DECLARE CURSOR statement in its own BEGIN ... END block.
> >
[quoted text clipped - 4 lines]
> >
> DB2 for zOS presumably V7?
> Try a dynamic cursor declaration, that should work.
> -snip-
>>>> Wrap the DECLARE CURSOR statement in its own BEGIN ... END block.
[quoted text clipped - 22 lines]
> compiles. Wrapping that in an extra begin/end gets the above error
> message.
Well, yes, that's what you said. Here is what I meant:
CREATE PROCEDURE p()
BEGIN
DECLARE var CHAR(1);
DECLARE txt VARCHAR(100);
DECLARE stmt STATEMENT;
DECLARE cur CURSOR WITH RETURN FOR stmt;
SET txt = 'SELECT * FROM SYSIBM.SYSDUMMY1 WHERE IBMREQD = ?';
PREPARE stmt FROM txt;
SET var = 'Y';
OPEN cur USING var;
END
@
CALL P()
@
Result set 1
--------------
IBMREQD
-------
Y
1 record(s) selected.
Return Status = 0
Cheers
Serge

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
J. Moreno - 27 Apr 2006 19:27 GMT
-snip nested compound statement not building inside stored procedure-
> > compiles. Wrapping that in an extra begin/end gets the above error
> > message.
> >
> Well, yes, that's what you said. Here is what I meant:
Thanks for the example, I think I understand now.
> CREATE PROCEDURE p()
> BEGIN
[quoted text clipped - 7 lines]
> OPEN cur USING var;
> END
Doesn't build. LINE 14 COL 17 UNSUPPORTED DATA TYPE DISTINCT TYPE
ENCOUNTERED IN SQL VARIABLE STMT
Off to do some more googling...

Signature
J. Moreno
Serge Rielau - 27 Apr 2006 20:34 GMT
> -snip nested compound statement not building inside stored procedure-
>>> compiles. Wrapping that in an extra begin/end gets the above error
[quoted text clipped - 20 lines]
>
> Off to do some more googling...
Try removing
DECLARE stmt STATEMENT;
Cheers
Serge

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
J. Moreno - 27 Apr 2006 21:59 GMT
-snip-
> >> CREATE PROCEDURE p()
> >> BEGIN
[quoted text clipped - 15 lines]
> Try removing
> DECLARE stmt STATEMENT;
That works. Thanks, I'll get the hang of this eventually.

Signature
J. Moreno
Serge Rielau - 28 Apr 2006 01:41 GMT
> -snip-
>>>> CREATE PROCEDURE p()
[quoted text clipped - 17 lines]
>
> That works. Thanks, I'll get the hang of this eventually.
Me too. I just learned why for DB2 for LUW that DECLARE is optional.
What we do for compatibility with the elder brother... :-)
Cheers
Serge

Signature
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab