Error 1311 occurs when a MySQL stored program references a local, INOUT, or OUT variable before it has been assigned a value.
MySQL Error 1311: ER_SP_UNINIT_VAR means a stored procedure, trigger, or function is using a variable that has never been set. Initialize the variable with DECLARE ... DEFAULT, SET, or SELECT ... INTO before the first read to resolve the error.
Referring to uninitialized variable %s
MySQL raises Error 1311 when a stored routine, trigger, or event references a variable that has not yet been initialized.
The server prevents reading an undefined value to avoid unpredictable results.
The error appears immediately after the first read of the uninitialized variable, halting the statement and rolling back the current block if necessary.
The error surfaces in MySQL 5.7, 8.0, and later whenever a local variable, INOUT parameter, or OUT parameter is read before a value is assigned with SET, SELECT ...
INTO, or a DEFAULT clause.
It frequently happens inside IF conditions, cursor loops, and expressions that attempt to concatenate or compare an uninitialized variable.
Leaving variables uninitialized risks null propagation, wrong calculations, and inconsistent business logic. Fixing the issue ensures deterministic results and cleaner code.
.
Yes. MySQL aborts the current statement and propagates the error up the call stack, rolling back only the statement, not the entire transaction unless autocommit is off.
No. MySQL does not provide a session variable to ignore uninitialized variables. Proper initialization is required.
Yes. If you explicitly SET a variable to NULL, it is considered initialized. The error only appears when you read a variable that has never been assigned any value.
Galaxy’s linting engine detects uninitialized local variables in stored program scripts and highlights them in the editor before you execute the code.