MySQL 实验室 因为专注,所以专业。

  • 首页
  • 博客
  • 下载
  • 文档
  • 工具
  • 知识库
  • 培训及服务
  • MySQL 5.1 Reference Manual :: 11 Functions and Operators
    • MySQL 5.1 Reference Manual
    • Preface, Notes, Licenses
    • 1 General Information
    • 2 Installing and Upgrading MySQL
    • 3 Tutorial
    • 4 MySQL Programs
    • 5 MySQL Server Administration
    • 6 Backup and Recovery
    • 7 Optimization
    • 8 Language Structure
    • 9 Internationalization and Localization
    • 10 Data Types
    • 11 Functions and Operators
    • 12 SQL Statement Syntax
    • 13 Storage Engines
    • 14 High Availability and Scalability
    • 15 MySQL Enterprise Monitor
    • 16 Replication
    • 17 MySQL Cluster NDB 6.X/7.X
    • 18 Partitioning
    • 19 Stored Programs and Views
    • 20 INFORMATION_SCHEMA Tables
    • 21 Connectors and APIs
    • 22 Extending MySQL
    • A MySQL 5.1 Frequently Asked Questions
    • B Errors, Error Codes, and Common Problems
    • C MySQL Change History
    • D Restrictions and Limits
    • Index
    • Standard Index
    • C Function Index
    • Command Index
    • Function Index
    • INFORMATION_SCHEMA Index
    • Transaction Isolation Level Index
    • JOIN Types Index
    • Operator Index
    • Option Index
    • Privileges Index
    • SQL Modes Index
    • Status Variable Index
    • Statement/Syntax Index
    • System Variable Index

    Chapter 11. Functions and Operators

    Table of Contents     [+/-]

    11.1. Operator and Function Reference
    11.2. Operators     [+/-]
    11.2.1. Operator Precedence
    11.2.2. Type Conversion in Expression Evaluation
    11.2.3. Comparison Functions and Operators
    11.2.4. Logical Operators
    11.3. Control Flow Functions
    11.4. String Functions     [+/-]
    11.4.1. String Comparison Functions
    11.4.2. Regular Expressions
    11.5. Numeric Functions     [+/-]
    11.5.1. Arithmetic Operators
    11.5.2. Mathematical Functions
    11.6. Date and Time Functions
    11.7. What Calendar Is Used By MySQL?
    11.8. Full-Text Search Functions     [+/-]
    11.8.1. Natural Language Full-Text Searches
    11.8.2. Boolean Full-Text Searches
    11.8.3. Full-Text Searches with Query Expansion
    11.8.4. Full-Text Stopwords
    11.8.5. Full-Text Restrictions
    11.8.6. Fine-Tuning MySQL Full-Text Search
    11.9. Cast Functions and Operators
    11.10. XML Functions
    11.11. Other Functions     [+/-]
    11.11.1. Bit Functions
    11.11.2. Encryption and Compression Functions
    11.11.3. Information Functions
    11.11.4. Miscellaneous Functions
    11.12. Functions and Modifiers for Use with GROUP BY Clauses     [+/-]
    11.12.1. GROUP BY (Aggregate) Functions
    11.12.2. GROUP BY Modifiers
    11.12.3. GROUP BY and HAVING with Hidden Columns
    11.13. Spatial Extensions     [+/-]
    11.13.1. Introduction to MySQL Spatial Support
    11.13.2. The OpenGIS Geometry Model
    11.13.3. Supported Spatial Data Formats
    11.13.4. Creating a Spatially Enabled MySQL Database
    11.13.5. Analyzing Spatial Information
    11.13.6. Optimizing Spatial Analysis
    11.13.7. MySQL Conformance and Compatibility
    11.14. Precision Math     [+/-]
    11.14.1. Types of Numeric Values
    11.14.2. DECIMAL Data Type Changes
    11.14.3. Expression Handling
    11.14.4. Rounding Behavior
    11.14.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. Expressions can be written using literal values, column values, NULL, built-in functions, stored functions, user-defined functions, and operators. This chapter describes the functions and operators that are allowed for writing expressions in MySQL. Instructions for writing stored functions and user-defined functions are given in Section 19.2, “Using Stored Routines (Procedures and Functions)”, and Section 22.3, “Adding New Functions to MySQL”. See Section 8.2.4, “Function Name Parsing and Resolution”, for the rules describing how the server interprets references to different kinds of functions.

    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.

    You can tell the MySQL server to accept spaces after function names by starting it with the --sql-mode=IGNORE_SPACE option. (See Section 5.1.7, “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.

    For the sake of brevity, most 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