Informix Error -598: Bad cursor name cursor-name.
Cause and resolution
Bad cursor name cursor-name.
Inside an SPL routine, a nonexistent cursor name was specified in an UPDATE/DELETE...WHERE CURRENT OF statement.
FOREACH cur1 FOR SELECT col INTO var FROM tab UPDATE tab SET col = proc(var) WHERE CURRENT OF bad_cur_name; -- error END FOREACH
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-598 fires when an SPL routine's UPDATE/DELETE ... WHERE CURRENT OF cursor-name names a
cursor that doesn't exist within the routine — per the official guidance, the most common form
of this is a FOREACH loop's implicit cursor referenced under the wrong name.
- A misspelled cursor name in
WHERE CURRENT OF, per the official guidance's example — referencing a name likebad_cur_namethat was never actually declared or named by the enclosingFOREACH. - A
FOREACHloop that doesn't explicitly name its cursor, where the routine then tries to reference it by an assumed name in a positioned UPDATE/DELETE, when no such named cursor exists. - A positioned UPDATE/DELETE placed outside the
FOREACHloop whose cursor it's trying to reference, so the cursor name simply isn't in scope at that point.
Solutions / Resolution
- Name the
FOREACHloop's cursor explicitly, and reference that exact name in the positioned UPDATE/DELETE:FOREACH cur1 FOR SELECT order_id, status INTO v_id, v_status FROM orders IF v_status = 'stale' THEN UPDATE orders SET status = 'cancelled' WHERE CURRENT OF cur1; END IF END FOREACH; - Review the spelling of the cursor name against the name given in the
FOREACHclause. - Confirm the positioned UPDATE/DELETE sits inside the loop whose cursor it references, since the cursor name is only in scope there.
Examples
The disallowed reference
FOREACH cur1 FOR SELECT order_id, status INTO v_id, v_status FROM orders
IF v_status = 'stale' THEN
UPDATE orders SET status = 'cancelled' WHERE CURRENT OF bad_cur_name;
-- -598: bad_cur_name doesn't exist; the loop's cursor is named cur1
END IF
END FOREACH;
Corrected
FOREACH cur1 FOR SELECT order_id, status INTO v_id, v_status FROM orders
IF v_status = 'stale' THEN
UPDATE orders SET status = 'cancelled' WHERE CURRENT OF cur1;
END IF
END FOREACH;
Diagnostic Checks
- Confirm the
FOREACHclause names its cursor explicitly, and that every positioned UPDATE/DELETE inside it uses that exact name.
Related Errors / Related Topics
- -507 — "Cursor cursor-name not found." The same underlying condition (a positioned
UPDATE/DELETE referencing a cursor that isn't open under that name), in ordinary embedded SQL
rather than specifically within an SPL routine's
FOREACH.
Almost always a FOREACH cursor referenced under the wrong name — name the loop's cursor
explicitly and match it exactly in the positioned UPDATE/DELETE.