1974
MariaDBERRORCommonStored RoutinesHIGH confidence
Variable is a LOCAL variable
Production Risk
None — statement is rejected.
What this means
A SET statement attempted to set a session or global variable but the name matches a local variable in the current stored routine scope. The two cannot be confused.
Why it happens
- 1SET @@local.x inside a stored procedure where x is also the name of a local variable.
- 2Confusion between local routine variables and session system variables with the same name.
How to reproduce
trigger — this will error
trigger — this will error
-- Inside a stored procedure with DECLARE x INT: SET @@local.x = 1; -- x is a local variable, not a session variable
expected output
ERROR 1974 (HY000): Variable 'x' is a LOCAL variable.
Fix
Rename the local variable to avoid collision with system variable names
Rename the local variable to avoid collision with system variable names
DECLARE v_x INT DEFAULT 0;
Why this works
Using a distinct prefix (e.g., v_) for local variables avoids collisions with system variable names.
Sources
Official documentation ↗
MySQL 8.0 — 1974 ER_LOCAL_VARIABLE
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev