SQLCODE=-501, SQLSTATE=24501 with Cursor

I have written one procedure. I am getting the below error. Can someone help me with this.

Create procedure p1() declare cur1 cursor WITH HOLD for STMT1; DECLARE CONTINUE HANDLER FOR SQLSTATE '24501' BEGIN OPEN index_list ; set exitcode = 1; END ; set TEXT =(); PREPARE STMT1 FROM TEXT; OPEN cur1 ; FETCH FROM cur1 INTO VAR2, VAR1 ; WHILE (SQLCODE = 0) DO EXECUTE IMMEDIATE 'SET PASSTHRU SAMPLE' ; ---- ----- EXECUTE IMMEDIATE 'SET PASSTHRU RESET' ; FETCH FROM cur1 INTO VAR2, VAR1 ; END WHILE; 

This is my code outline. My problem is After that 'SET PASSTHRU RESET', cursor is getting closed & the second fetch is failing with the below error.even I specified the curos a WITH HOLD option.

error: The cursor specified in a FETCH statement or CLOSE statement is not open or a cursor variable in a cursor scalar function reference is not open.. SQLCODE=-501, SQLSTATE=24501, DRIVER=4.17.30 Run of routine failed.

can some one please let me know, what i have to add here. I am new bee for db2 & never met with this scenario. That is why I am asking the experts.

3

Related questions 1 Db2 error : SQL0901N, SQLSTATE=58004 1 DB2 ERROR on OPEN Cursor, Sqlcode : -818 0 db2 SQLCODE=-243, SQLSTATE=36001 ERROR Related questions 1 Db2 error : SQL0901N, SQLSTATE=58004 1 DB2 ERROR on OPEN Cursor, Sqlcode : -818 0 db2 SQLCODE=-243, SQLSTATE=36001 ERROR 1 SQL0206N "SQLSTATE" is not valid in the context where it is used. SQLSTATE=42703 32 SqlException: DB2 SQL error: SQLCODE: -302, SQLSTATE: 22001, SQLERRMC: null 0 getting error SQLCODE=-10, SQLSTATE=42603, SQLERRMC='), 0 DB2 SQL Error: SQLCODE=-911, SQLSTATE=40001, SQLERRMC=68 9 DB2 ERRORCODE=-4229, SQLSTATE=null 1 DB2 SQLCODE -433, SQLSTATE 22001 13 DB2 SQL error sqlcode=-104 sqlstate=42601 Load 7 more related questions Show fewer related questions

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like