- 14.1 内置函数和操作符参考14.1 Built-In Function and Operator Reference
- 14.2 可加载函数参考14.2 Loadable Function Reference
- 14.3 表达式求值中的类型转换14.3 Type Conversion in Expression Evaluation
- 14.4 操作符14.4 Operators
- 14.5 流程控制函数14.5 Flow Control Functions
- 14.6 数值函数和运算符14.6 Numeric Functions and Operators
- 14.7 日期和时间函数14.7 Date and Time Functions
- 14.8 字符串函数和操作符14.8 String Functions and Operators
- 14.9 全文搜索函数14.9 Full-Text Search Functions
- 14.9.1 自然语言全文搜索14.9.1 Natural Language Full-Text Searches
- 14.9.2 布尔全文搜索14.9.2 Boolean Full-Text Searches
- 14.9.3 带查询扩展的全文搜索14.9.3 Full-Text Searches with Query Expansion
- 14.9.4 全文停用词14.9.4 Full-Text Stopwords
- 14.9.5 全文限制14.9.5 Full-Text Restrictions
- 14.9.6 微调 MySQL 全文搜索14.9.6 Fine-Tuning MySQL Full-Text Search
- 14.9.7 为全文索引添加用户定义的排序规则14.9.7 Adding a User-Defined Collation for Full-Text Indexing
- 14.9.8 ngram 全文解析器14.9.8 ngram Full-Text Parser
- 14.9.9 MeCab 全文解析器插件14.9.9 MeCab Full-Text Parser Plugin
- 14.10 类型转换函数和操作符14.10 Cast Functions and Operators
- 14.11 XML 函数14.11 XML Functions
- 14.12 位函数和操作符14.12 Bit Functions and Operators
- 14.13 加密和压缩函数14.13 Encryption and Compression Functions
- 14.14 锁定函数14.14 Locking Functions
- 14.15 信息函数14.15 Information Functions
- 14.16 空间分析函数14.16 Spatial Analysis Functions
- 14.16.1 空间函数参考14.16.1 Spatial Function Reference
- 14.16.2 空间函数参数处理14.16.2 Argument Handling by Spatial Functions
- 14.16.3 从 WKT 值创建几何值的函数14.16.3 Functions That Create Geometry Values from WKT Values
- 14.16.4 从 WKB 值创建几何值的函数14.16.4 Functions That Create Geometry Values from WKB Values
- 14.16.5 MySQL 特定的创建几何值函数14.16.5 MySQL-Specific Functions That Create Geometry Values
- 14.16.6 几何格式转换函数14.16.6 Geometry Format Conversion Functions
- 14.16.7 几何属性函数14.16.7 Geometry Property Functions
- 14.16.8 空间操作函数14.16.8 Spatial Operator Functions
- 14.16.9 测试几何对象空间关系的函数14.16.9 Functions That Test Spatial Relations Between Geometry Objects
- 14.16.10 空间 Geohash 函数14.16.10 Spatial Geohash Functions
- 14.16.11 空间 GeoJSON 函数14.16.11 Spatial GeoJSON Functions
- 14.16.12 空间聚合函数14.16.12 Spatial Aggregate Functions
- 14.16.13 空间便捷函数14.16.13 Spatial Convenience Functions
- 14.17 JSON 函数14.17 JSON Functions
- 14.17.1 JSON 函数参考14.17.1 JSON Function Reference
- 14.17.2 创建 JSON 值的函数14.17.2 Functions That Create JSON Values
- 14.17.3 搜索 JSON 值的函数14.17.3 Functions That Search JSON Values
- 14.17.4 修改 JSON 值的函数14.17.4 Functions That Modify JSON Values
- 14.17.5 返回 JSON 值属性的函数14.17.5 Functions That Return JSON Value Attributes
- 14.17.6 JSON 表函数14.17.6 JSON Table Functions
- 14.17.7 JSON 模式验证函数14.17.7 JSON Schema Validation Functions
- 14.17.8 JSON 实用函数14.17.8 JSON Utility Functions
- 14.18 复制函数14.18 Replication Functions
- 14.19 聚合函数14.19 Aggregate Functions
- 14.20 窗口函数14.20 Window Functions
- 14.21 性能模式函数14.21 Performance Schema Functions
- 14.22 内部函数14.22 Internal Functions
- 14.23 杂项函数14.23 Miscellaneous Functions
- 14.24 精度数学14.24 Precision Math
表达式可以在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.
默认情况下,函数名和其后括号之间不能有空格。这有助于 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