CREATE PROCEDURE NYCIKCP.LIB_SEQ UNCE_GEN(IN "@ADB_DIVIS ION" VARCHAR(32))
SPECIFIC LIB_SEQUNCE_GEN
MODIFIES SQL DATA
NOT DETERMINISTIC
NULL CALL
LANGUAGE SQL
BEGIN
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INT DEFAULT 0;
DECLARE INT_COUNTER INTEGER DEFAULT 1;
DECLARE VC_P_ID VARCHAR(32) DEFAULT NULL;
DECLARE CURSOR_MAST_TAB LE CURSOR FOR
--SELECT P_ID FROM LIBRA_PROCESS_M AST MAST WHERE MAST.DIVISION_I D='adv_GCS' AND MAST.ADDENDUM IS NULL ORDER BY MAST.P_NAME;
SELECT P_ID FROM LIBRA_PROCESS_M AST MAST WHERE MAST.DIVISION_I D=@ADB_DIVISION AND MAST.ADDEND_PAR ENT IS NULL ORDER BY MAST.P_NAME;
OPEN CURSOR_MAST_TAB LE;
FETCH FROM CURSOR_MAST_TAB LE INTO VC_P_ID;
WHILE(SQLSTATE = '00000') DO
UPDATE LIBRA_PROCESS_M AST MAST SET MAST.DIV_SHORT_ CODE_INDEX=INT_ COUNTER WHERE MAST.P_ID=VC_P_ ID;
FETCH FROM CURSOR_MAST_TAB LE INTO VC_P_ID;
SET INT_COUNTER=INT _COUNTER+1;
END WHILE;
CLOSE CURSOR_MAST_TAB LE;
END
;
this proc when run, run for ages and does not terminate. When i debug this proc from Embarcadero DBArtisan i could detect that the while loop is causing to run the proc, as its not getting terminated even after the sqlstate changes from '00000' to '02000' when end of cursor record is reached.
I have no clue why the while loop returns true for the check SQLSTATE = '00000') when the sqlstate vale is '02000'.
i have tried replacing the while loop with if loop, i am still facing the issue. i belive the issue is not with the while or for loop but the way the check is performed in the proc.
could someone suggest the correct way to perform the check and the exit procedure for end of cursor.
refrence:
http://publib.boulder. ibm.com/infocenter/db2luw/v9/index.jsp?topic =/com.ibm.db2.udb .apdv.sql.doc/doc/c0024361.htm
SPECIFIC LIB_SEQUNCE_GEN
MODIFIES SQL DATA
NOT DETERMINISTIC
NULL CALL
LANGUAGE SQL
BEGIN
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INT DEFAULT 0;
DECLARE INT_COUNTER INTEGER DEFAULT 1;
DECLARE VC_P_ID VARCHAR(32) DEFAULT NULL;
DECLARE CURSOR_MAST_TAB LE CURSOR FOR
--SELECT P_ID FROM LIBRA_PROCESS_M AST MAST WHERE MAST.DIVISION_I D='adv_GCS' AND MAST.ADDENDUM IS NULL ORDER BY MAST.P_NAME;
SELECT P_ID FROM LIBRA_PROCESS_M AST MAST WHERE MAST.DIVISION_I D=@ADB_DIVISION AND MAST.ADDEND_PAR ENT IS NULL ORDER BY MAST.P_NAME;
OPEN CURSOR_MAST_TAB LE;
FETCH FROM CURSOR_MAST_TAB LE INTO VC_P_ID;
WHILE(SQLSTATE = '00000') DO
UPDATE LIBRA_PROCESS_M AST MAST SET MAST.DIV_SHORT_ CODE_INDEX=INT_ COUNTER WHERE MAST.P_ID=VC_P_ ID;
FETCH FROM CURSOR_MAST_TAB LE INTO VC_P_ID;
SET INT_COUNTER=INT _COUNTER+1;
END WHILE;
CLOSE CURSOR_MAST_TAB LE;
END
;
this proc when run, run for ages and does not terminate. When i debug this proc from Embarcadero DBArtisan i could detect that the while loop is causing to run the proc, as its not getting terminated even after the sqlstate changes from '00000' to '02000' when end of cursor record is reached.
I have no clue why the while loop returns true for the check SQLSTATE = '00000') when the sqlstate vale is '02000'.
i have tried replacing the while loop with if loop, i am still facing the issue. i belive the issue is not with the while or for loop but the way the check is performed in the proc.
could someone suggest the correct way to perform the check and the exit procedure for end of cursor.
refrence:
http://publib.boulder. ibm.com/infocenter/db2luw/v9/index.jsp?topic =/com.ibm.db2.udb .apdv.sql.doc/doc/c0024361.htm
Comment