Chapter 12 Functions and Operators第12章 函数和运算符

Table of Contents目录

12.1 Built-In Function and Operator Reference内置函数和运算符参考
12.2 Loadable Function Reference可加载函数引用
12.3 Type Conversion in Expression Evaluation表达式求值中的类型转换
12.4 Operators运算符优先级
12.4.1 Operator Precedence运算符优先级
12.4.2 Comparison Functions and Operators比较函数和运算符
12.4.3 Logical Operators逻辑运算符
12.4.4 Assignment Operators赋值运算符
12.5 Flow Control Functions流程控函数
12.6 Numeric Functions and Operators数值函数和运算符
12.6.1 Arithmetic Operators算术运算符
12.6.2 Mathematical Functions数学函数
12.7 Date and Time Functions日期和时间函数
12.8 String Functions and Operators字符串函数和运算符
12.8.1 String Comparison Functions and Operators字符串比较函数和运算符
12.8.2 Regular Expressions正则表达式
12.8.3 Character Set and Collation of Function Results字符集与函数结果的排序
12.9 What Calendar Is Used By MySQL?MySQL使用什么日历?
12.10 Full-Text Search Functions全文搜索函数
12.10.1 Natural Language Full-Text Searches自然语言全文搜索
12.10.2 Boolean Full-Text Searches布尔全文搜索
12.10.3 Full-Text Searches with Query Expansion带查询扩展的全文搜索
12.10.4 Full-Text Stopwords全文停止字
12.10.5 Full-Text Restrictions全文限制
12.10.6 Fine-Tuning MySQL Full-Text Search微调MySQL全文搜索
12.10.7 Adding a User-Defined Collation for Full-Text Indexing为全文索引添加用户定义的排序规则
12.10.8 ngram Full-Text Parserngram全文分析器
12.10.9 MeCab Full-Text Parser PluginMeCab全文解析器插件
12.11 Cast Functions and OperatorsCast函数和运算符
12.12 XML FunctionsXML函数
12.13 Bit Functions and Operators位函数和运算符
12.14 Encryption and Compression Functions加密和压缩函数
12.15 Locking Functions锁定函数
12.16 Information Functions信息函数
12.17 Spatial Analysis Functions空间分析函数
12.17.1 Spatial Function Reference空间函数参考
12.17.2 Argument Handling by Spatial Functions空间函数的参数处理
12.17.3 Functions That Create Geometry Values from WKT Values从WKT值创建几何图形值的函数
12.17.4 Functions That Create Geometry Values from WKB Values从WKB值创建几何图形值的函数
12.17.5 MySQL-Specific Functions That Create Geometry Values创建几何值的特定于MySQL的函数
12.17.6 Geometry Format Conversion Functions几何格式转换函数
12.17.7 Geometry Property Functions几何特性函数
12.17.8 Spatial Operator Functions空间运算符函数
12.17.9 Functions That Test Spatial Relations Between Geometry Objects测试几何体对象之间空间关系的函数
12.17.10 Spatial Geohash Functions空间Geohash函数
12.17.11 Spatial GeoJSON Functions空间GeoJSON函数
12.17.12 Spatial Aggregate Functions空间聚集函数
12.17.13 Spatial Convenience Functions空间便利函数
12.18 JSON FunctionsJSON函数
12.18.1 JSON Function ReferenceJSON函数引用
12.18.2 Functions That Create JSON Values创建JSON值的函数
12.18.3 Functions That Search JSON Values搜索JSON值的函数
12.18.4 Functions That Modify JSON Values修改JSON值的函数
12.18.5 Functions That Return JSON Value Attributes返回JSON值属性的函数
12.18.6 JSON Table FunctionsJSON表函数
12.18.7 JSON Schema Validation FunctionsJSON架构验证函数
12.18.8 JSON Utility FunctionsJSON实用函数
12.19 Functions Used with Global Transaction Identifiers (GTIDs)与全局事务标识符(GTID)一起使用的函数
12.20 Aggregate Functions聚合函数
12.20.1 Aggregate Function Descriptions聚合函数描述
12.20.2 GROUP BY ModifiersGROUP BY修饰符
12.20.3 MySQL Handling of GROUP BYGROUP BY的MySQL处理
12.20.4 Detection of Functional Dependence函数依赖性检测
12.21 Window Functions窗口函数
12.21.1 Window Function Descriptions窗口函数描述
12.21.2 Window Function Concepts and Syntax窗口函数概念和语法
12.21.3 Window Function Frame Specification窗口函数框架规范文档
12.21.4 Named Windows命名窗口
12.21.5 Window Function Restrictions窗口函数局限性
12.22 Performance Schema Functions性能架构函数
12.23 Internal Functions内部函数
12.24 Miscellaneous Functions其他函数
12.25 Precision Math精确数学
12.25.1 Types of Numeric Values数值类型
12.25.2 DECIMAL Data Type Characteristics十进制数据类型特征
12.25.3 Expression Handling表达式处理
12.25.4 Rounding Behavior舍入行为
12.25.5 Precision Math Examples精确数学示例

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. 表达式可以在SQL语句中的多个位置使用,例如在SELECT语句的ORDER BY子句或HAVING子句中,在SELECTDELETEUPDATE语句的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值。

Note注意

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
12.1 Built-In Function and Operator Reference
12.2 Loadable Function Reference
12.3 Type Conversion in Expression Evaluation
12.4 Operators
12.5 Flow Control Functions
12.6 Numeric Functions and Operators
12.7 Date and Time Functions
12.8 String Functions and Operators
12.9 What Calendar Is Used By MySQL?
12.11 Cast Functions and Operators
12.12 XML Functions
12.13 Bit Functions and Operators
12.14 Encryption and Compression Functions
12.15 Locking Functions
12.16 Information Functions
12.17 Spatial Analysis Functions
12.18 JSON Functions
12.19 Functions Used with Global Transaction Identifiers (GTIDs)
12.20 Aggregate Functions
12.21 Window Functions
12.22 Performance Schema Functions
12.23 Internal Functions
12.24 Miscellaneous Functions
12.25 Precision Math