SET
语法
SET variable_assignment [, variable_assignment] ... variable_assignment: user_var_name = expr | [GLOBAL | SESSION] system_var_name = expr | [@@global. | @@session. | @@]system_var_name = expr
可以在任意表达式中使用下面的语法设置用户变量:
user_var_name:= expr
描述
SET
语句可以为影响服务端或客户端的不同变量类型进行赋值。老版本的MySQL采用SET OPTION
,但是不赞成使用带有OPTION
的SET
语法,且其在MariaDB 10.0版本中已经移除。
要为基于每查询(per-query)(从MariaDB 10.1.2之后开始的功能)的变量赋值,参见SET STATEMENT
。
要查看服务端系统变量,可参见SHOW VARIABLES
。
Server System Variables列出了所有的系统变量。
示例
SHOW VARIABLES WHERE Variable_name LIKE "aria_group_commit%"; +----------------------------+-------+ | Variable_name | Value | +----------------------------+-------+ | aria_group_commit | none | | aria_group_commit_interval | 0 | +----------------------------+-------+ SET GLOBAL aria_group_commit="HARD"; SET GLOBAL aria_group_commit_interval=100; SHOW VARIABLES WHERE Variable_name LIKE "aria_group_commit%"; +----------------------------+-------+ | Variable_name | Value | +----------------------------+-------+ | aria_group_commit | hard | | aria_group_commit_interval | 100 | +----------------------------+-------+
直接赋值:
SELECT (@a:=1); +---------+ | (@a:=1) | +---------+ | 1 | +---------+ SELECT @a; +------+ | @a | +------+ | 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.