User variables are written as @var_name. : User Defined Variables « Select Query « MySQL Tutorial






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>








2.22.User Defined Variables
2.22.1.User variables are written as @var_name.
2.22.2.You can also assign a value to a user variable in statements other than SET
2.22.3.Using User-Defined Variables
2.22.4.Use user-defined variable in the where statement
2.22.5.Create dynamic sql command