Quote:
|
Originally Posted by n_i
Not if you separate the cursor loop and the handler into its own BEGIN...END block.
|
So from your suggestion NI, I now have the following, which seems to work. Thanks for the help.
CREATE PROCEDURE CURSOR_TEST ()
SPECIFIC CURSOR_TEST
LANGUAGE SQL
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN
-- declare these for DB2, it sets them implicitely (see Application Development Guide: Programming Server Applications)
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE var1 varchar(20);
DECLARE at_end SMALLINT DEFAULT 0;
DECLARE not_found CONDITION FOR SQLSTATE '02000';
DECLARE c1 CURSOR FOR
SELECT field1
FROM someTable
WHERE field2 = 'X'
OPEN c1;
WHILE at_end = 0 DO
P2: BEGIN
DECLARE CONTINUE HANDLER for not_found SET at_end = 1;
FETCH c1 INTO var1;
END P2;
-- do something...
END WHILE;
CLOSE c1;
END P1