Mysql has temporary variables. MySQL variables can be divided into temporary variables, local variables, session variables and global variables; temporary variables are user variables, which need to be used with the "@" character and do not need to be declared. The usage is "set @name=value;" and "select @ num=value;".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
MySQL official manual divides variables into system variables and user variables. User variables are user-defined variables added to a statement, and then this variable can be assigned to other variables, or in another statement. Call etc.
However, in some places, variables are also divided according to usage:
1. Temporary variables (in the case of the @ symbol, which is the user variable introduced in the mysql manual);
2. Local variables (declare mode);
3. Session variables;
Declare standard variables
DECLARE end_flag INT DEFAULT 0;
Temporary variable@ (no declaration required)
Only works locally Usage one: set @name=value;set @num=1; set @num:=1;Usage two: select @num=value;
select @num:=1; select @num:=字段名 from 表名 where ……
Global variables @@
System variables can only be read and cannot be modified, such as @@errorLocal variables (declare declaration variables)
declare declaration variables: The declare declaration keyword can be used to define variables, generally used in stored procedures or custom functions a) , declare variable Usage: declare a v1 variable, defined as int type, the default value is 0;declare v1 INT default 0;b), declare variable using After declaration, the variable is normal It is in a stored procedure or customization, so it is written between the begin and end keywords. The outside cannot be directly defined and then called, so declare is also called a local variable [Related recommendations :
mysql video tutorial】
The above is the detailed content of Does mysql have temporary variables?. For more information, please follow other related articles on the PHP Chinese website!