1299
MySQLerrorstored-procedureshigh confidence

LEAVE/ITERATE can only be used inside a loop/block

Production Risk

Low — compile-time error; routine not created.

What this means

A LEAVE or ITERATE statement references a label that does not correspond to a surrounding loop or BEGIN...END block.

Why it happens
  1. 1Typo in the label name
  2. 2LEAVE used outside any loop or block
  3. 3Label defined in an outer scope not visible here
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE p() BEGIN LEAVE nonexistent_label; END;

expected output

ERROR 1299 (42000): LEAVE with no matching label: 'nonexistent_label'

Fix

Match label names exactly

Match label names exactly
CREATE PROCEDURE p() BEGIN my_loop: LOOP LEAVE my_loop; END LOOP; END;

Why this works

Ensure LEAVE/ITERATE label matches the enclosing block label.

Sources
Official documentation ↗

MySQL 8.0 — 1299 ER_SP_LILABEL_MISMATCH

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

← All MySQL errors