这是我的存储过程:
CREATE PROCEDURE PROC1()
LANGUAGE SQL
BEGIN
DECLARE EOF INT DEFAULT 0;
DECLARE SQLCODE INT DEFAULT 0;
DECLARE var_MYID INT;
DECLARE PCURSOR CURSOR FOR SELECT MYID FROM MYTABLE
OPEN PCURSOR;
WHILE EOF = 0 DO
FETCH FROM PCURSOR INTO var_MYID;
IF SQLCODE = 100 THEN
SET EOF = 1;
ELSE
-- nested cursor goes here
END IF;
END WHILE;
CLOSE PCURSOR;
END
SQLCODE = 100更新(我调试时总是0)。所以它变成了无限循环。我没有使用
DECLARE CONTINUE HANDLER FOR NOT FOUND SET EOF = 1;
因为我将使用另一个嵌套游标。