Mega Code Archive

 
Categories / MySQL Tutorial / Select Query
 

User variables are written as @var_name

The variable name var_name may consist of alphanumeric characters from the current character set, '.','_', and $. One way to set a user-defined variable is by issuing a SET statement: SET @var_name = expr [, @var_name = expr] ... mysql> mysql> SET @t1=0, @t2=1, @t3=2; Query OK, 0 rows affected (0.00 sec) mysql> mysql> select @t1; +------+ | @t1  | +------+ | 0    | +------+ 1 row in set (0.00 sec) mysql> select @t2; +------+ | @t2  | +------+ | 1    | +------+ 1 row in set (0.00 sec) mysql> select @t3; +------+ | @t3  | +------+ | 2    | +------+ 1 row in set (0.00 sec) mysql>