Informix Error -33039: Updates are not allowed in singleton select.
Cause and resolution
Updates are not allowed in singleton select.
You have an UPDATE statement in combination with a SELECT statement that returns only one row. The UPDATE statement requires a cursor that has been declared FOR UPDATE. See the DECLARE, SELECT, and UPDATE statements in the IBM Informix Guide to SQL: Syntax for more information about cursors.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-33039 fires when an UPDATE is combined with a SELECT that returns only one row
without a FOR UPDATE cursor — per the official guidance, such an UPDATE requires a
cursor declared FOR UPDATE.
- An
UPDATEcombined with a singletonSELECT, without aFOR UPDATEcursor, per the official guidance — the direct, only cause.
Solutions / Resolution
- Declare a cursor
FOR UPDATEfor theSELECT, per the official guidance, consulting theDECLARE/SELECT/UPDATEentries in the IBM Informix Guide to SQL: Syntax.
Examples
An UPDATE tied to a singleton SELECT without FOR UPDATE
SELECT total INTO :amt FROM orders WHERE order_id = 1001;
UPDATE orders SET total = :amt * 2 WHERE order_id = 1001;
-- -33039: the singleton SELECT has no FOR UPDATE cursor
Corrected
DECLARE upd_cur CURSOR FOR
SELECT total FROM orders WHERE order_id = 1001 FOR UPDATE;
OPEN upd_cur;
FETCH upd_cur INTO :amt;
UPDATE orders SET total = :amt * 2 WHERE CURRENT OF upd_cur;
Diagnostic Checks
- Check whether the singleton
SELECTfeeding theUPDATEuses aFOR UPDATEcursor, and add one if missing.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -33039 in this set yet.
An UPDATE was tied to a singleton SELECT without a FOR UPDATE cursor — declare one.