This is a read-only copy of the MariaDB Knowledgebase generated on 2024-12-22. For the latest, interactive version please visit https://mariadb.com/kb/.

赋值操作符(:=)

语法

var_name := expr

描述

该赋值操作符用于为一个变量进行赋值。操作符右边的值将赋值给操作符左边的变量。

不像=操作符,:=操作符总是可以用来为变量赋值。(译者注:使用select语句赋值时不能使用"="进行赋值)。

该操作符可以为用户自定义变量user-defined variables和本地变量local variables赋值。

当要为多个变量赋值相同的值时,可以考虑使用LAST_VALUE()函数。

示例

 SELECT @x := 10;
+----------+
| @x := 10 |
+----------+
|       10 |
+----------+

SELECT @x, @y := @x;
+------+----------+
| @x   | @y := @x |
+------+----------+
|   10 |       10 |
+------+----------+
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.