1319
MySQLerrorstored-procedureshigh confidence
Undeclared variable
Production Risk
Low — compile-time error; routine not created.
What this means
A stored routine referenced a local variable that was never declared with DECLARE.
Why it happens
- 1Typo in variable name
- 2Variable declared in a nested block and referenced outside it
- 3Missing DECLARE statement
How to reproduce
trigger — this will error
trigger — this will error
CREATE PROCEDURE p() BEGIN SET undeclared_var = 1; END;
expected output
ERROR 1319 (42000): Undeclared variable: undeclared_var
Fix
Add a DECLARE statement
Add a DECLARE statement
DECLARE undeclared_var INT DEFAULT 0;
Why this works
All local variables in stored routines must be explicitly declared.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1319 ER_SP_UNDECLARED_VAR
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev