1316
MySQLerrorstored-procedureshigh confidence
Undefined CURSOR
Production Risk
Low — compile-time error; routine not created.
What this means
OPEN, FETCH, or CLOSE referenced a cursor name that has not been declared in the current scope.
Why it happens
- 1Typo in cursor name
- 2Cursor declared in a nested block not visible in the current block
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE p() BEGIN OPEN undeclared_cur; END;
expected output
ERROR 1316 (42000): Undefined CURSOR: undeclared_cur
Fix
Declare the cursor before use
Declare the cursor before use
DECLARE cur CURSOR FOR SELECT id FROM t;
Why this works
Cursor declarations must appear before OPEN/FETCH/CLOSE.
Sources
Official documentation ↗
MySQL 8.0 — 1316 ER_SP_CURSOR_MISMATCH
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev