http://dev.mysql.com/doc/refman/5.0/en/expressions.html
http://dev.mysql.com/doc/refman/5.0/en/functions.html
Chapter 12. Functions and Operators
Table of Contents [+/-]
- 12.1. Function and Operator Reference
- 12.2. Type Conversion in Expression Evaluation
- 12.3. Operators [+/-]
- 12.4. Control Flow Functions
- 12.5. String Functions [+/-]
- 12.6. Numeric Functions and Operators [+/-]
- 12.7. Date and Time Functions
- 12.8. What Calendar Is Used By MySQL?
- 12.9. Full-Text Search Functions [+/-]
- 12.10. Cast Functions and Operators
- 12.11. Bit Functions
- 12.12. Encryption and Compression Functions
- 12.13. Information Functions
- 12.14. Miscellaneous Functions
- 12.15. Functions and Modifiers for Use with
GROUP BY
Clauses [+/-] - 12.16. Spatial Extensions [+/-]
- 12.17. Precision Math [+/-]
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
, orUPDATE
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 permitted for writing expressions in MySQL. Instructions for writing stored functions and user-defined functions are given in Section 18.2, “Using Stored Routines (Procedures and Functions)”, and Section 21.2, “Adding New Functions to MySQL”. See Section 9.2.3, “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.
EXPRESSIONS SYNTAX:
expr
:expr
ORexpr
|expr
||expr
|expr
XORexpr
|expr
ANDexpr
|expr
&&expr
| NOTexpr
| !expr
|boolean_primary
IS [NOT] {TRUE | FALSE | UNKNOWN} |boolean_primary
boolean_primary
:boolean_primary
IS [NOT] NULL |boolean_primary
<=>predicate
|boolean_primary
comparison_operator
predicate
|boolean_primary
comparison_operator
{ALL | ANY} (subquery
) |predicate
comparison_operator
: = | >= | > | <= | < | <> | !=predicate
:bit_expr
[NOT] IN (subquery
) |bit_expr
[NOT] IN (expr
[,expr
] ...) |bit_expr
[NOT] BETWEENbit_expr
ANDpredicate
|bit_expr
SOUNDS LIKEbit_expr
|bit_expr
[NOT] LIKEsimple_expr
[ESCAPEsimple_expr
] |bit_expr
[NOT] REGEXPbit_expr
|bit_expr
bit_expr
:bit_expr
|bit_expr
|bit_expr
&bit_expr
|bit_expr
<<bit_expr
|bit_expr
>>bit_expr
|bit_expr
+bit_expr
|bit_expr
-bit_expr
|bit_expr
*bit_expr
|bit_expr
/bit_expr
|bit_expr
DIVbit_expr
|bit_expr
MODbit_expr
|bit_expr
%bit_expr
|bit_expr
^bit_expr
|bit_expr
+interval_expr
|bit_expr
-interval_expr
|simple_expr
simple_expr
:literal
|identifier
|function_call
|simple_expr
COLLATEcollation_name
|param_marker
|variable
|simple_expr
||simple_expr
| +simple_expr
| -simple_expr
| ~simple_expr
| !simple_expr
| BINARYsimple_expr
| (expr
[,expr
] ...) | ROW (expr
,expr
[,expr
] ...) | (subquery
) | EXISTS (subquery
) | {identifier
expr
} |match_expr
|case_expr
|interval_expr
Notes:
For literal value syntax, see Section 9.1, “Literal Values”.
For identifier syntax, see Section 9.2, “Schema Object Names”.
Variables can be user variables, system variables, or stored program local variables or parameters:
- User variables: Section 9.4, “User-Defined Variables”
- System variables: Section 5.1.5, “Using System Variables”
- Local variables: Section 13.6.4.1, “Local Variable
DECLARE
Syntax”
param_marker
is '?'
as used in prepared statements for placeholders. See Section 13.5.1, “PREPARE
Syntax”.(subquery
)
indicates a subquery that returns a single value; that is, a scalar subquery. SeeSection 13.2.9.1, “The Subquery as Scalar Operand”.{identifier
expr
}
is ODBC escape syntax and is accepted for ODBC compatibility. The value isexpr
. The curly braces in the syntax should be written literally; they are not metasyntax as used elsewhere in syntax descriptions.interval_expr
represents a time interval. The syntax is INTERVAL expr
unit
, where unit
is a specifier such as HOUR
, DAY
, or WEEK
. For the full list of unit
specifiers, see the description of theDATE_ADD()
function in Section 12.7, “Date and Time Functions”.
The meaning of some operators depends on the SQL mode:
- By default,
||
is a logicalOR
operator. WithPIPES_AS_CONCAT
enabled,||
is string concatenation, with a precedence between^
and the unary operators. - By default,
!
has a higher precedence thanNOT
as of MySQL 5.0.2. For earlier versions, or from 5.0.2 on withHIGH_NOT_PRECEDENCE
enabled,!
andNOT
have the same precedence.
No comments:
Post a Comment