Home > Database > Mysql Tutorial > body text

Does mysql have temporary variables?

青灯夜游
Release: 2023-02-09 13:43:24
Original
3034 people have browsed it

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;".

Does mysql have temporary variables?

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;

  • ##4 , Global variables (that is, system variables).

In fact, the classification is just for the convenience of recording and learning. The key point is to master the usage principles

Declare standard variables

DECLARE end_flag INT DEFAULT 0;
Copy after login

Temporary variable@ (no declaration required)

Only works locally

Usage one: set @name=value;

set @num=1; set @num:=1;
Copy after login

Usage two: select @num=value;

select @num:=1; select @num:=字段名 from 表名 where ……
Copy after login

Global variables @@

System variables can only be read and cannot be modified, such as @@error

Local 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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!