Home >Database >Mysql Tutorial >How Do I Declare and Use Variables in MySQL?
Detailed explanation of MySQL variables
MySQL supports multiple types of variables for storing and manipulating data:
User-defined variables
SET @变量名 = 值;
Local variables
DECLARE 变量名 数据类型 DEFAULT 值;
Server system variables
SHOW VARIABLES LIKE '%变量名%';
View current settings. Code Example
The following code demonstrates the use of user-defined variables:
<code class="language-sql">SET @起始值 = 1, @结束值 = 10; SELECT * FROM places WHERE place BETWEEN @起始值 AND @结束值;</code>
User-defined variables @起始值
and @结束值
are used here. The SET statement initializes these two variables. The BETWEEN operator filters results where the place column value is within the specified range.
The above is the detailed content of How Do I Declare and Use Variables in MySQL?. For more information, please follow other related articles on the PHP Chinese website!