1318
MySQLerrorstored-procedureshigh confidence

Cursor is not open

Production Risk

Low — runtime error inside stored routine.

What this means

FETCH or CLOSE was called on a cursor that has not been opened.

Why it happens
  1. 1Forgetting to call OPEN before FETCH
  2. 2Handler or early exit path bypassed the OPEN statement
How to reproduce
trigger — this will error
trigger — this will error
FETCH cur INTO v;  -- without prior OPEN cur

expected output

ERROR 1318 (24000): Cursor is not open

Fix

Open the cursor first

Open the cursor first
OPEN cur; FETCH cur INTO v;

Why this works

Always OPEN before FETCH.

Sources
Official documentation ↗

MySQL 8.0 — 1318 ER_SP_CURSOR_NOT_OPEN

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors