SQLCODE -504
SQL0504 Cursor not declared
- IBM message text
- Cursor &1 not declared.
- SQLCODE
- -504
- SQLSTATE
- 34000
Most common cause
The cursor is used before its DECLARE in the source. The precompiler reads the source in physical order, not in execution order.
Other causes
- The cursor name is spelt differently in DECLARE and OPEN or FETCH.
- DECLARE in one procedure and use in another.
How to fix it
Move the DECLARE physically above OPEN and FETCH in the source, in the same procedure.
Text and codes from IBM documentation for 7.6. Checked on .