Informix Error -413
-413 Insert attempted on unopen cursor.
This INSERT statement names a cursor that has never been opened or that has been closed. Review the program logic, and check that it will open the cursor before this point and not accidentally close it. An insert cursor is automatically closed by a COMMIT WORK or ROLLBACK WORK statement.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-413 is the insert-cursor counterpart of -400: an INSERT through a cursor was attempted
without the cursor being currently open — either it was never opened, or it was already closed,
including implicitly closed by COMMIT WORK/ROLLBACK WORK.
- An
INSERTissued before the correspondingOPENcursor statement. - An
INSERTissued afterCLOSEon the same cursor, without reopening it. COMMIT WORK/ROLLBACK WORKimplicitly closing the insert cursor, since these automatically close insert cursors — anINSERTafter that point fails even without an explicitCLOSEin the code.
Solutions / Resolution
- Review program logic to ensure the cursor is opened before every
INSERTthrough it, per the official guidance. - Reopen the cursor after any
COMMIT WORK/ROLLBACK WORKif further inserts through it are needed, since these statements automatically close insert cursors. - Check for a premature
CLOSEif the cursor is closing earlier than the program logic expects.
Examples
Reopening after a commit
DECLARE curs1 CURSOR FOR INSERT INTO orders (order_id, customer_id) VALUES (?, ?);
OPEN curs1;
PUT curs1 (1001, 42);
COMMIT WORK;
PUT curs1 (1002, 43);
-- -413: COMMIT WORK closed curs1 automatically
-- Fix — reopen before continuing:
OPEN curs1;
PUT curs1 (1002, 43);
Diagnostic Checks
- Confirm the cursor was opened before the failing
INSERT. - Check for an intervening
CLOSE,COMMIT WORK, orROLLBACK WORKbetween theOPENand the failingINSERT.
Related Errors / Related Topics
- -400 — "Fetch attempted on unopen cursor." The closely related sibling — the same
underlying open/close lifecycle issue, applied to
FETCHinstead ofINSERT. - -398 — "Cursor manipulation must be within a transaction." A related cursor/transaction interaction restriction, on logged databases specifically.
COMMIT WORK/ROLLBACK WORK automatically close insert cursors — reopen explicitly after either
one if more inserts through the same cursor are needed.