Type Conversion in Expression Evaluation
871
Name
Description
VARIANCE()
[972]
Return the population standard variance
VERSION()
[964]
Returns a string that indicates the MySQL server version
WEEK()
[932]
Return the week number
WEEKDAY()
[933]
Return the weekday index
WEEKOFYEAR()
[933]
Return the calendar week of the date (0-53)
XOR
[881]
Logical XOR
YEAR()
[933]
Return the year
YEARWEEK()
[934]
Return the year and week
12.2. Type Conversion in Expression Evaluation
When an operator is used with operands of different types, type conversion occurs to make the
operands compatible. Some conversions occur implicitly. For example, MySQL automatically converts
numbers to strings as necessary, and vice versa.
mysql>
SELECT 1+'1';
-> 2
mysql>
SELECT CONCAT(2,' test');
-> '2 test'
It is also possible to convert a number to a string explicitly using the
CAST()
[948]
function.
Conversion occurs implicitly with the
CONCAT()
[887]
function because it expects string arguments.
mysql>
SELECT 38.8, CAST(38.8 AS CHAR);
-> 38.8, '38.8'
mysql>
SELECT 38.8, CONCAT(38.8);
-> 38.8, '38.8'
See later in this section for information about the character set of implicit number-to-string conversions.
The following rules describe how conversion occurs for comparison operations:
• If one or both arguments are
NULL
, the result of the comparison is
NULL
, except for the
NULL
-safe
<=>
[876]
equality comparison operator. For
NULL <=> NULL
, the result is true. No conversion is
needed.
• If both arguments in a comparison operation are strings, they are compared as strings.
• If both arguments are integers, they are compared as integers.
• Hexadecimal values are treated as binary strings if not compared to a number.
• If one of the arguments is a
TIMESTAMP
or
DATETIME
column and the other argument is a
constant, the constant is converted to a timestamp before the comparison is performed. This is
done to be more ODBC-friendly. Note that this is not done for the arguments to
IN()
[878]
! To be
safe, always use complete datetime, date, or time strings when doing comparisons. For example, to
achieve best results when using
BETWEEN
[877]
with date or time values, use
CAST()
[948]
to
explicitly convert the values to the desired data type.
• If one of the arguments is a decimal value, comparison depends on the other argument. The
arguments are compared as decimal values if the other argument is a decimal or integer value, or as
floating-point values if the other argument is a floating-point value.
• In all other cases, the arguments are compared as floating-point (real) numbers.
For information about conversion of values from one temporal type to another, see
Section 11.1.5.7,
“Conversion Between Date and Time Types”
.
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...