ORA-01001: invalid cursor
Oracle SQL Error: ORA-01001: invalid cursor
Cause:
Either a host language program call specified an invalid cursor or the value of the MAXOPENCURSORS option in the precompiler command were too small. All cursors must be opened using the OPEN call before being referenced in any of the following calls: SQL, DESCRIBE, NAME, DEFINE, BIND, EXEC, FETCH, and CLOSE.
Solution:
Check the error call statement. Specify a correct LDA area or open the cursor as required. If there is no problem with the cursor, it may be necessary to increase the MAXOPENCURSORS option value before precompiling.
Example:
DECLARE CURSOR c1 IS SELECT * FROM books; rec books%ROWTYPE; BEGIN LOOP FETCH c1 INTO rec; EXIT WHEN c1%NOTFOUND; DBMS_OUTPUT.PUT_LINE(rec.NAME); END LOOP; END;
Output:
ORA-01001: invalid cursor
ORA-06512: at line 6
Correct
DECLARE CURSOR c1 IS SELECT * FROM books; rec books%ROWTYPE; BEGIN OPEN c1; LOOP FETCH c1 INTO rec; EXIT WHEN c1%NOTFOUND; DBMS_OUTPUT.PUT_LINE(rec.NAME); END LOOP; CLOSE c1; END;
Output:
anonymous block completed