自定义变量
以@打头,如@value。
使用SET设置值,如下:
SET @var_name = expr [, @var_name = expr] ...
会话级别的变量,当前连接会话中可见。在其他会话中不可见(有个例外,Exception: A user with access to the Performance Schema user_variables_by_thread table can see all user variables for all sessions.)
存储过程中的变量
系统变量、自定义变量以及使用DECLARE定义的变量。
DECLARE语法如下:
DECLARE var_name [, var_name] ... type [DEFAULT value]
Prepared statement不能使用DECLARE定义的变量,因为此变量的作用域只在当前存储过程中,而Prepared statement是会话级别。