8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 14 函数和运算符
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

第 14 章 函数与运算符Chapter 14 Functions and Operators

表达式可以在SQL语句的多个位置使用,例如在SELECT语句的ORDER BY或HAVING子句中,在SELECT、DELETE或UPDATE语句的WHERE子句中,或在SET语句中。表达式可以使用来自多个来源的值来编写,例如字面值、列值、NULL、变量、内置函数和运算符、可加载函数以及存储函数(存储对象的一种)。Expressions can be used at several points in SQL statements, such as in the ORDER BY or HAVING clauses of SELECT statements, in the WHERE clause of a SELECT, DELETE, or UPDATE statement, or in SET statements. 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).

本章介绍了允许在 MySQL 中编写表达式的内置函数和操作符。有关可加载函数和存储函数的信息,请参见 第 7.7 节,“MySQL 服务器可加载函数”,以及 第 27.2 节,“使用存储例程”。有关服务器如何解释对不同类型函数的引用的规则,请参见 第 11.2.5 节,“函数名称解析和解决”。This chapter describes the built-in functions and operators that are permitted for writing expressions in MySQL. For information about loadable functions and stored functions, see Section 7.7, “MySQL Server Loadable Functions”, and Section 27.2, “Using Stored Routines”. For the rules describing how the server interprets references to different kinds of functions, see Section 11.2.5, “Function Name Parsing and Resolution”.

包含 NULL 的表达式始终产生 NULL 值,除非特定函数或操作符的文档中另有说明。An expression that contains NULL always produces a NULL value unless otherwise indicated in the documentation for a particular function or operator.

Note

默认情况下,函数名和其后括号之间不能有空格。这有助于 MySQL 解析器区分函数调用和恰好与某个函数同名的表或列的引用。然而,函数参数周围允许有空格。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. However, spaces around function arguments are permitted.

要告诉 MySQL 服务器在函数名后接受空格,可以通过在启动时使用 --sql-mode=IGNORE_SPACE 选项。(参见 第 7.1.11 节,“服务器 SQL 模式”。) 各个客户端程序也可以通过在 mysql_real_connect() 中使用 CLIENT_IGNORE_SPACE 选项来请求这种行为。在任一情况下,所有函数名都成为保留字。To tell the MySQL server to accept spaces after function names by starting it with the --sql-mode=IGNORE_SPACE option. (See Section 7.1.11, “Server SQL Modes”.) Individual client programs can request this behavior by using the CLIENT_IGNORE_SPACE option for mysql_real_connect(). In either case, all function names become reserved words.

为了简洁起见,本章中的一些示例显示了mysql程序的输出的简略形式。不是以这种格式显示示例:For the sake of brevity, some examples in this chapter display the output from the mysql program in abbreviated form. 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