1413
MySQLerrorstored-procedureshigh confidence
Duplicate handler declared in the same block
Production Risk
Low — compile-time error; routine not created.
What this means
Two DECLARE HANDLER statements in the same BEGIN...END block handle the same condition.
Why it happens
- 1Copy-paste error resulting in two handlers for the same SQLSTATE or condition
How to reproduce
trigger — this will error
trigger — this will error
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=2;
expected output
ERROR 1413 (HY000): Duplicate handler declared in the same block
Fix
Merge into a single handler
Merge into a single handler
DECLARE CONTINUE HANDLER FOR NOT FOUND BEGIN SET done=1; /* combined logic */ END;
Why this works
One handler per condition per block.
Sources
Official documentation ↗
MySQL 8.0 — 1413 ER_SP_DUP_HANDLER
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev