MySql 中文参考指南

Chapter 14 Functions and Operators

目录

Table of Contents

表达式可以在 SQL 语句的几个点使用,例如,在 SELECT 语句的 ORDER BYHAVING 子句中,在 SELECTDELETEUPDATE 语句的 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 中编写表达式的允许内置函数和运算符。有关可加载函数和存储函数的信息,请参阅 Section 7.7, “MySQL Server Loadable Functions”Section 27.2, “Using Stored Routines”。有关服务器解释对不同类型函数引用的规则,请参阅 Section 11.2.5, “Function Name Parsing and Resolution”

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 选项启动 MySQL 服务器。(请参见 Section 7.1.11, “Server SQL Modes” 。)各个客户端程序可以通过对 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