Rounding Behavior
1005
• If strict mode is enabled, inserts and updates involving division by zero are prohibited, and an error
occurs.
In other words, inserts and updates involving expressions that perform division by zero can be treated
as errors, but this requires
ERROR_FOR_DIVISION_BY_ZERO
[536]
in addition to strict mode.
Suppose that we have this statement:
INSERT INTO t SET i = 1/0;
This is what happens for combinations of strict and
ERROR_FOR_DIVISION_BY_ZERO
[536]
modes.
sql_mode
[495]
Value
Result
''
(Default)
No warning, no error;
i
is set to
NULL
.
strict
No warning, no error;
i
is set to
NULL
.
ERROR_FOR_DIVISION_BY_ZERO
[536]
Warning, no error;
i
is set to
NULL
.
strict,
ERROR_FOR_DIVISION_BY_ZERO
[536]
Error condition; no row is inserted.
For inserts of strings into numeric columns, conversion from string to number is handled as follows if
the string has nonnumeric contents:
• A string that does not begin with a number cannot be used as a number and produces an error in
strict mode, or a warning otherwise. This includes the empty string.
• A string that begins with a number can be converted, but the trailing nonnumeric portion is truncated.
If the truncated portion contains anything other than spaces, this produces an error in strict mode, or
a warning otherwise.
12.17.4. Rounding Behavior
This section discusses precision math rounding for the
ROUND()
[913]
function and for inserts into
columns with exact-value types (
DECIMAL
and integer).
The
ROUND()
[913]
function rounds differently depending on whether its argument is exact or
approximate:
• For exact-value numbers,
ROUND()
[913]
uses the “round half up” rule: A value with a fractional
part of .5 or greater is rounded up to the next integer if positive or down to the next integer if
negative. (In other words, it is rounded away from zero.) A value with a fractional part less than .5 is
rounded down to the next integer if positive or up to the next integer if negative.
• For approximate-value numbers, the result depends on the C library. On many systems, this means
that
ROUND()
[913]
uses the “round to nearest even” rule: A value with any fractional part is
rounded to the nearest even integer.
The following example shows how rounding differs for exact and approximate values:
mysql>
SELECT ROUND(2.5), ROUND(25E-1);
+------------+--------------+
| ROUND(2.5) | ROUND(25E-1) |
+------------+--------------+
| 3 | 2 |
+------------+--------------+
For inserts into a
DECIMAL
or integer column, the target is an exact data type, so rounding uses “round
half away from zero,” regardless of whether the value to be inserted is exact or approximate:
mysql>
CREATE TABLE t (d DECIMAL(10,0));
Query OK, 0 rows affected (0.00 sec)
mysql>
INSERT INTO t VALUES(2.5),(2.5E0);
Содержание 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 ...