Table of Contents目录
Expressions can be used at several points in SQL statements, such as in the 表达式可以在SQL语句中的多个位置使用,例如在ORDER BY
or HAVING
clauses of SELECT
statements, in the WHERE
clause of a SELECT
, DELETE
, or UPDATE
statement, or in SET
statements. SELECT
语句的ORDER BY
子句或HAVING
子句中,在SELECT
、DELETE
或UPDATE
语句的WHERE
子句中,或在SET
语句中。Expressions can be written using values from several sources, such as literal values, column values, 可以使用来自多个源的值来编写表达式,例如文字值、列值、NULL
, variables, built-in functions and operators, loadable functions, and stored functions (a type of stored object).NULL
、变量、内置函数和运算符、可加载函数和存储函数(存储对象的一种类型)。
This chapter describes the built-in functions and operators that are permitted for writing expressions in MySQL. 本章介绍允许在MySQL中编写表达式的内置函数和运算符。For information about loadable functions and stored functions, see Section 5.7, “MySQL Server Loadable Functions”, and Section 25.2, “Using Stored Routines”. 有关可加载函数和存储函数的信息,请参阅第5.7节“MySQL Server可加载函数”和第25.2节“使用存储例程”。For the rules describing how the server interprets references to different kinds of functions, see Section 9.2.5, “Function Name Parsing and Resolution”.有关描述服务器如何解释对不同类型函数的引用的规则,请参见第9.2.5节“函数名解析和解析”。
An expression that contains 除非文档中对特定函数或运算符另有说明,否则包含NULL
always produces a NULL
value unless otherwise indicated in the documentation for a particular function or operator.NULL
的表达式总是生成NULL
值。
By default, there must be no whitespace between a function name and the parenthesis following it. 默认情况下,函数名和它后面的括号之间不能有空格。This helps the MySQL parser distinguish between function calls and references to tables or columns that happen to have the same name as a function. 这有助于MySQL解析器区分函数调用和对恰好与函数同名的表或列的引用。However, spaces around function arguments are permitted.但是,函数参数周围允许有空格。
To tell the MySQL server to accept spaces after function names by starting it with the 以--sql-mode=IGNORE_SPACE
option. --sql-mode=IGNORE_SPACE
选项开头,告诉MySQL服务器接受函数名后面的空格。(See Section 5.1.11, “Server SQL Modes”.) (见第5.1.11节“服务器SQL模式”。)Individual client programs can request this behavior by using the 个别客户端程序可以使用CLIENT_IGNORE_SPACE
option for mysql_real_connect()
. mysql_real_connect()
的client_IGNORE_SPACE
选项来请求此行为。In either case, all function names become reserved words.在这两种情况下,所有函数名都成为保留字。
For the sake of brevity, some examples in this chapter display the output from the mysql program in abbreviated form. 为了简洁起见,本章中的一些示例以缩写形式显示mysql程序的输出。Rather than showing examples in this format:并不是以这种格式显示示例:
mysql> SELECT MOD(29,9);
+-----------+
| mod(29,9) |
+-----------+
| 2 |
+-----------+
1 rows in set (0.00 sec)
This format is used instead:而是改用以下格式:
mysql> SELECT MOD(29,9);
-> 2