1501
MySQLERRORNotableStored RoutinesHIGH confidence

Multiple definition of same condition in stored routine handler

Production Risk

Low — compile-time error; the routine will not be created.

What this means

ER_MULTIPLE_DEF_CONDITION_ERROR (1501, SQLSTATE HY000) is raised when a stored routine declares multiple condition handlers for the same condition.

Why it happens
  1. 1DECLARE CONTINUE HANDLER FOR SQLEXCEPTION defined twice in the same scope
  2. 2Duplicate DECLARE HANDLER FOR the same SQLSTATE or error code
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE my_proc()
BEGIN
  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @err = 1;
  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @err = 2;  -- Duplicate!
END;

expected output

ERROR 1501 (HY000): Multiple definitions of the same condition for a HANDLER

Fix

Remove the duplicate handler declaration

Remove the duplicate handler declaration
CREATE PROCEDURE my_proc()
BEGIN
  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  BEGIN
    SET @err = 1;
    -- Handle the error in one place
  END;
  SELECT * FROM my_table;
END;

Why this works

Each condition type can only have one handler per scope; consolidate logic into a single handler.

Sources
Official documentation ↗

MySQL 8.0 — 1501 ER_MULTIPLE_DEF_CONDITION_ERROR

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

← All MySQL errors