Variables in sql server must be declared first and then assigned a value:
Local variables are marked with one @, and global variables are marked with two @s (commonly used global variables are generally already defined);
The syntax for declaring local variables: declare @variable Name data type; for example: declare @num int;
Assignment: There are two methods (@num is the variable name, value is the value)
set @num=value; or select @num=value;
If you want To obtain a field value in a query statement, you can use select to assign a value to a variable, as follows:
select @num=Field name from table name where...
Variables in MySQL do not need to be declared in advance. When using them, use "@variable name" directly. "Just use it.
First usage: set @num=1; or set @num:=1; //Variables are used to save data here, use @num variables directly
Second usage: select @num:=1; Or select @num:=field name from table name where...
Pay attention to the above two assignment symbols. You can use "=" or ":=" when using set, but you must use ":= assignment" when using select
The above is the content of mysql variable declaration and value assignment. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!