3143
MySQLERRORNotableStored RoutinesHIGH confidence
CASE statement has no matching WHEN clause and no ELSE
Production Risk
Medium — runtime error in stored procedures can abort a transaction.
What this means
A CASE statement in a stored procedure was executed but none of the WHEN conditions matched the operand, and no ELSE clause was provided to handle unmatched cases.
Why it happens
- 1CASE statement missing an ELSE branch.
- 2The CASE operand value is NULL or an unexpected value not covered by any WHEN clause.
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE test_case(IN v INT)
BEGIN
CASE v
WHEN 1 THEN SELECT 'one';
WHEN 2 THEN SELECT 'two';
END CASE;
END;expected output
ERROR 3143 (20000): Case not found for CASE statement
Fix
Add an ELSE clause
Add an ELSE clause
CASE v WHEN 1 THEN SELECT 'one'; WHEN 2 THEN SELECT 'two'; ELSE SELECT 'other'; END CASE;
Why this works
ELSE handles all values not matched by WHEN clauses, preventing the error.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3143 ER_SP_CASE_NOT_FOUND
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev