-504 CURSOR NAME cursor-name IS NOT DECLARED
Explanation
- Cursor cursor-name was not declared (using the DECLARE CURSOR statement) or allocated (using the ALLOCATE CURSOR statement) in the application program or SQL routine before it was referenced.
- Cursor cursor-name was referenced in a positioned UPDATE or DELETE statement which is not a supported operation for an allocated cursor.
- Cursor cursor-name was allocated, but a CLOSE cursor statement naming cursor-name was issued and deallocated the cursor before this cursor reference.
- Cursor cursor-name was allocated, but a ROLLBACK operation occurred and deallocated the cursor before this cursor reference.
- Cursor cursor-name was allocated, but its associated cursor declared in a stored procedure was not declared WITH HOLD, and a COMMIT operation occurred and deallocated the cursor before this cursor reference. The COMMIT operation can be either explicit (the COMMIT statement) or implicit (that is, a stored procedure defined as COMMIT_ON_RETURN = 'Y' was called before this cursor reference).
- Cursor cursor-name was allocated, but its associated stored procedure was called again since the cursor was allocated, new result sets were returned, and cursor cursor-name was deallocated.
- The declaration of a cursor cursor-name was not in scope for the reference to a cursor named cursor-name.
System action
The statement cannot be processed.
Programmer response
Check the application program or SQL routine for completeness and for a possible spelling error in the cursor declaration or allocation. The declaration for or allocation of a cursor must appear in an application program or SQL routine before SQL statements that reference the cursor.
If the cursor-name was <UNKNOWN>, the cursor was not successfully declared or allocated. This error can occur if SQL(Db2) was used, and a warning message was issued during precompilation. Check the precompile output for warning messages on the DECLARE CURSOR or ALLOCATE CURSOR statement, and correct the statement.
- After the COMMIT, ROLLBACK, or CLOSE operation, call the associated stored procedure again, and reissue the ASSOCIATE LOCATORS and ALLOCATE CURSOR statements.
- For COMMIT, declare the associated cursor in the stored procedure WITH HOLD so the COMMIT operation does not deallocate the cursor.
For an allocated cursor, if the associated stored procedure was called again and new result sets were returned since the cursor was allocated, reissue the ASSOCIATE LOCATORS and ALLOCATE CURSOR statements.
SQLSTATE
34000