Variables in Stored Programs 2798 13.6.4.2 Local Variable Scope and Resolution 13.6.4.1 Local Variable DECLARE Statement and stored routines (procedures and functions) can be declared to take parameters that communicate values between the routine and its caller. For information about the scope of local variables and how MySQL resolves ambiguous names, see Section 13.6.4.2, “Local Variable Scope and Resolution” . It is not permitted to assign the value  DEFAULT  to stored procedure or function parameters or stored program local variables (for example with a  SET  var_name  = DEFAULT  statement). In MySQL 8.0, this results in a syntax error. DECLARE  var_name  [,  var_name ] ...  type  [DEFAULT  value ] This statement declares local variables within stored programs. To provide a default value for a variable, include a  DEFAULT  clause. The value can be specified as an expression; it need not be a constant. If the DEFAULT  clause is missing, the initial value is  NULL . Local variables are treated like stored routine parameters with respect to data type and overflow checking. See Section 13.1.17, “CREATE PROCEDURE and CREATE FUNCTION Statements” . Variable declarations must appear before cursor or handler declarations. Local variable names are not case-sensitive. Permissible characters and quoting rules are the same as for other identifiers, as described in Section 9.2, “Schema Object Names” . The scope of a local variable is the  BEGIN ... END  block within which it is declared. The variable can be referred to in blocks nested within the declaring block, except those blocks that declare a variable with the same name. For examples of variable declarations, see Section 13.6.4.2, “Local Variable Scope and Resolution” . The scope of a local variable is the  BEGIN ... END  block within which it is declared. The variable can be referred to in blocks nested within the declaring block, except those blocks that declare a variable with the same name. Because local variables are in scope only during stored program execution, references to them are not permitted in prepared statements created within a stored program. Prepared statement scope is the current session, not the stored program, so the statement could be executed after the program ends, at which point the variables would no longer be in scope. For example,  SELECT ... INTO  local_var  cannot be used as a prepared statement. This restriction also applies to stored procedure and function parameters. See Section 13.5.1, “PREPARE Statement” . A local variable should not have the same name as a table column. If an SQL statement, such as a SELECT ... INTO  statement, contains a reference to a column and a declared local variable with the •Results from queries can be retrieved into local variables using  SELECT ... INTO  var_list  or by opening a cursor and using  FETCH ... INTO  var_list . See Section 13.2.10.1, “SELECT ... INTO Statement” , and Section 13.6.6, “Cursors” . •Variables can be set directly with the  SET  statement. See Section 13.7.6.1, “SET Syntax for Variable Assignment” . •To declare local variables, use the  DECLARE  statement, as described in Section 13.6.4.1, “Local Variable DECLARE Statement” .