1302
MySQLwarningstored-procedureshigh confidence
Referring to uninitialized variable
Production Risk
Low — value is NULL; may cause silent logic errors in the routine.
What this means
A stored routine referenced a variable before assigning it a value; the variable is NULL.
Why it happens
- 1Variable declared with DECLARE but no DEFAULT or SET before first use
- 2Logic path that skips the initialization assignment
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE p() BEGIN DECLARE v INT; SELECT v; END;
expected output
Warning 1302 (HY000): Referring to uninitialized variable v
Fix
Initialize with a default
Initialize with a default
DECLARE v INT DEFAULT 0;
Why this works
Provides a safe starting value.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1302 ER_SP_UNINIT_VAR
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev