1321
MariaDBwarningstored-procedureshigh confidence
No data — zero rows fetched, selected, or processed
Production Risk
Low — expected behaviour; handle gracefully with a NOT FOUND handler.
What this means
A FETCH on a cursor returned no data because the result set is exhausted; this is the standard cursor loop termination signal (SQLSTATE 02000).
Why it happens
- 1Cursor has iterated through all rows
- 2The cursor query returned an empty result set from the start
How to reproduce
trigger — this will error
trigger — this will error
FETCH cur INTO v; -- after all rows consumed
expected output
Warning/SQLSTATE 02000: No data — zero rows fetched, selected, or processed
Fix
Declare a NOT FOUND handler to exit the loop
Declare a NOT FOUND handler to exit the loop
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
Why this works
Sets a flag when FETCH exhausts the cursor, enabling clean loop exit.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1321 ER_SP_FETCH_NO_DATA
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev