SET Variable

You are viewing an old version of this article. View the current version here.

语法

SET var_name = expr [, var_name = expr] ...

Contents

  1. 语法
  2. See also

SET语句在存储过程stored programs中是普通SET语句的一个扩展功能。 变量引用的时候,可以引用存储过程内部、全局系统变量或用户自定义变量。

存储过程中的SET语句是作为预先存在的SET的一部分实现的。 存储程序中的SET语句是作为已有的SET语法的一部分实现的。 这允许扩展SET a = x,b = y,...的语法,其中可以混合不同的变量类型(本地声明的变量,全局系统变量和会话系统变量,用户定义的变量)。也允许组合局部变量和仅对系统变量有意义的一些选项; 在这种情况下,虽然会识别选项,但却会忽略它。

SET可为本地变量local variables和用户自定义变量user-defined variables赋值。

当通过查询返回的列值来为多个变量赋值时,应优先考虑使用SELECT INTO

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

以下是一个用户自定义变量的赋值示例:

SET @x = 1;

See also

Comments

Comments loading...
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.