Subject DECLARE CURSOR in a SP
Author Bill Meaney
Can I

DECLARE cCurs CURSOR FOR <select>;

in a stored procedure? I've not been successful so far.

In the past I've processed multiple queries with nested FOR SELECTs as in:

FOR SELECT col_1
FROM tbl_1
INTO :vCol1
DO BEGIN
FOR SELECT col_2
FROM tbl_2
WHERE col_1 = :vCol1
INTO :vCol2
DO BEGIN
<some processing>;
END
END


What I need is to process multiple queries in parallel and was hoping to use
multiple CURSORS as in:

CREATE PROCEDURE Parallel
AS
DECLARE VARIABLE vCol1 INTEGER;
DECLARE VARIABLE vCol2 INTEGER;
DECLARE VARIABLE vContinue INTEGER;

DECLARE cFirst CURSOR FOR
SELECT col_1
FROM tbl_1;

DECLARE cSecond CURSOR FOR
SELECT col_2
FROM tbl_2;

BEGIN
vContinue = 1;
OPEN cFirst;
OPEN cSecond;

FETCH cFirst INTO :vCol1;
IF (SQLCODE <> 100) THEN /* not EOF */
BEGIN
FETCH cSecond INTO :vCol2;
IF (SQLCODE = 100) THEN /* EOF */
vContinue = 0;
END
ELSE vContinue = 0; /* EOF of cFirst */

WHILE (vContinue = 1) DO
BEGIN
<some processing>
<Fetch cFirst as needed setting vContinue = 0 at EOF>
<Fetch cSecond as needed setting vContinue = 0 at EOF>
END

CLOSE cFirst;
CLOSE cSecond;
END

This is an over simplified version of what I have to do but should give you
an idea of what I'm trying to accomplish. Any ideas how I can do this in a
stored procedure?


Bill Meaney


[Non-text portions of this message have been removed]