Pre-General Availability Draft: 2017-05-29
System variables and user-defined variables can be used in stored
programs, just as they can be used outside stored-program context.
In addition, stored programs can use
define local variables, and stored routines (procedures and
functions) can be declared to take parameters that communicate
values between the routine and its caller.
Variables can be set directly with the
SETstatement. See Section 184.108.40.206, “SET Syntax for Variable Assignment”.
Results from queries can be retrieved into local variables using
SELECT ... INTOor by opening a cursor and using
FETCH ... INTO. See Section 220.127.116.11, “SELECT ... INTO Syntax”, and Section 14.6.6, “Cursors”.
For information about the scope of local variables and how MySQL resolves ambiguous names, see Section 18.104.22.168, “Local Variable Scope and Resolution”.
It is not permitted to assign the value
to stored procedure or function parameters or stored program local
variables (for example with a
statement). In MySQL 8.0, this results in a syntax
var_name = DEFAULT