# Chapter 12 Functions and Operators

**Table of Contents**

[12.1 Built-In Function and Operator Reference](built-in-function-reference.html)
[12.2 Loadable Function Reference](loadable-function-reference.html)
[12.3 Type Conversion in Expression Evaluation](type-conversion.html)
[12.4 Operators](non-typed-operators.html)
[12.4.1 Operator Precedence](operator-precedence.html)
[12.4.2 Comparison Functions and Operators](comparison-operators.html)
[12.4.3 Logical Operators](logical-operators.html)
[12.4.4 Assignment Operators](assignment-operators.html)
[12.5 Flow Control Functions](flow-control-functions.html)
[12.6 Numeric Functions and Operators](numeric-functions.html)
[12.6.1 Arithmetic Operators](arithmetic-functions.html)
[12.6.2 Mathematical Functions](mathematical-functions.html)
[12.7 Date and Time Functions](date-and-time-functions.html)
[12.8 String Functions and Operators](string-functions.html)
[12.8.1 String Comparison Functions and Operators](string-comparison-functions.html)
[12.8.2 Regular Expressions](regexp.html)
[12.8.3 Character Set and Collation of Function Results](string-functions-charset.html)
[12.9 What Calendar Is Used By MySQL?](mysql-calendar.html)
[12.10 Full-Text Search Functions](fulltext-search.html)
[12.10.1 Natural Language Full-Text Searches](fulltext-natural-language.html)
[12.10.2 Boolean Full-Text Searches](fulltext-boolean.html)
[12.10.3 Full-Text Searches with Query Expansion](fulltext-query-expansion.html)
[12.10.4 Full-Text Stopwords](fulltext-stopwords.html)
[12.10.5 Full-Text Restrictions](fulltext-restrictions.html)
[12.10.6 Fine-Tuning MySQL Full-Text Search](fulltext-fine-tuning.html)
[12.10.7 Adding a User-Defined Collation for Full-Text Indexing](full-text-adding-collation.html)
[12.10.8 ngram Full-Text Parser](fulltext-search-ngram.html)
[12.10.9 MeCab Full-Text Parser Plugin](fulltext-search-mecab.html)
[12.11 Cast Functions and Operators](cast-functions.html)
[12.12 XML Functions](xml-functions.html)
[12.13 Bit Functions and Operators](bit-functions.html)
[12.14 Encryption and Compression Functions](encryption-functions.html)
[12.15 Locking Functions](locking-functions.html)
[12.16 Information Functions](information-functions.html)
[12.17 Spatial Analysis Functions](spatial-analysis-functions.html)
[12.17.1 Spatial Function Reference](spatial-function-reference.html)
[12.17.2 Argument Handling by Spatial Functions](spatial-function-argument-handling.html)
[12.17.3 Functions That Create Geometry Values from WKT Values](gis-wkt-functions.html)
[12.17.4 Functions That Create Geometry Values from WKB Values](gis-wkb-functions.html)
[12.17.5 MySQL-Specific Functions That Create Geometry Values](gis-mysql-specific-functions.html)
[12.17.6 Geometry Format Conversion Functions](gis-format-conversion-functions.html)
[12.17.7 Geometry Property Functions](gis-property-functions.html)
[12.17.8 Spatial Operator Functions](spatial-operator-functions.html)
[12.17.9 Functions That Test Spatial Relations Between Geometry Objects](spatial-relation-functions.html)
[12.17.10 Spatial Geohash Functions](spatial-geohash-functions.html)
[12.17.11 Spatial GeoJSON Functions](spatial-geojson-functions.html)
[12.17.12 Spatial Aggregate Functions](spatial-aggregate-functions.html)
[12.17.13 Spatial Convenience Functions](spatial-convenience-functions.html)
[12.18 JSON Functions](json-functions.html)
[12.18.1 JSON Function Reference](json-function-reference.html)
[12.18.2 Functions That Create JSON Values](json-creation-functions.html)
[12.18.3 Functions That Search JSON Values](json-search-functions.html)
[12.18.4 Functions That Modify JSON Values](json-modification-functions.html)
[12.18.5 Functions That Return JSON Value Attributes](json-attribute-functions.html)
[12.18.6 JSON Table Functions](json-table-functions.html)
[12.18.7 JSON Schema Validation Functions](json-validation-functions.html)
[12.18.8 JSON Utility Functions](json-utility-functions.html)
[12.19 Functions Used with Global Transaction Identifiers (GTIDs)](gtid-functions.html)
[12.20 Aggregate Functions](aggregate-functions-and-modifiers.html)
[12.20.1 Aggregate Function Descriptions](aggregate-functions.html)
[12.20.2 GROUP BY Modifiers](group-by-modifiers.html)
[12.20.3 MySQL Handling of GROUP BY](group-by-handling.html)
[12.20.4 Detection of Functional Dependence](group-by-functional-dependence.html)
[12.21 Window Functions](window-functions.html)
[12.21.1 Window Function Descriptions](window-function-descriptions.html)
[12.21.2 Window Function Concepts and Syntax](window-functions-usage.html)
[12.21.3 Window Function Frame Specification](window-functions-frames.html)
[12.21.4 Named Windows](window-functions-named-windows.html)
[12.21.5 Window Function Restrictions](window-function-restrictions.html)
[12.22 Performance Schema Functions](performance-schema-functions.html)
[12.23 Internal Functions](internal-functions.html)
[12.24 Miscellaneous Functions](miscellaneous-functions.html)
[12.25 Precision Math](precision-math.html)
[12.25.1 Types of Numeric Values](precision-math-numbers.html)
[12.25.2 DECIMAL Data Type Characteristics](precision-math-decimal-characteristics.html)
[12.25.3 Expression Handling](precision-math-expressions.html)
[12.25.4 Rounding Behavior](precision-math-rounding.html)
[12.25.5 Precision Math Examples](precision-math-examples.html)

[]()[]()[]()

 Expressions can be used at several points in [SQL](glossary.html#glos_sql) statements, such as in the `ORDER BY` or `HAVING` clauses of [`SELECT`](select.html) statements, in the `WHERE` clause of a [`SELECT`](select.html), [`DELETE`](delete.html), or [`UPDATE`](update.html) statement, or in [`SET`](set-variable.html) 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).

 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 5.7, “MySQL Server Loadable Functions”](server-loadable-functions.html), and [Section 25.2, “Using Stored Routines”](stored-routines.html). For the rules describing how the server interprets references to different kinds of functions, see [Section 9.2.5, “Function Name Parsing and Resolution”](function-resolution.html).

 An expression that contains `NULL` always produces a `NULL` value unless otherwise indicated in the documentation for a particular function or operator.

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. 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`](server-options.html#option_mysqld_sql-mode) option. (See [Section 5.1.11, “Server SQL Modes”](sql-mode.html).) Individual client programs can request this behavior by using the `CLIENT_IGNORE_SPACE` option for [`mysql_real_connect()`](https://dev.mysql.com/doc/c-api/8.0/en/mysql-real-connect.html). 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**](mysql.html) 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
```

