Oracle 5.0 Reference Manual page 1028

Table of Contents

Advertisement

Before MySQL 5.0.2 (or in 5.0.2 and later, without strict mode), truncation to a legal value occurs:
mysql>
CREATE TABLE t (i TINYINT);
Query OK, 0 rows affected (0.01 sec)
mysql>
INSERT INTO t SET i = 128;
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql>
SELECT i FROM t;
+------+
| i
|
+------+
|
127 |
+------+
1 row in set (0.00 sec)
As of MySQL 5.0.2, an error occurs if strict mode is in effect:
mysql>
SET sql_mode='STRICT_ALL_TABLES';
Query OK, 0 rows affected (0.00 sec)
mysql>
CREATE TABLE t (i TINYINT);
Query OK, 0 rows affected (0.00 sec)
mysql>
INSERT INTO t SET i = 128;
ERROR 1264 (22003): Out of range value adjusted for column 'i' at row 1
mysql>
SELECT i FROM t;
Empty set (0.00 sec)
Example 5: In strict mode and with
causes an error, not a result of NULL.
Before MySQL 5.0.2 (or when not using strict mode in 5.0.2 or a later version), division by zero has a
result of NULL:
mysql>
CREATE TABLE t (i TINYINT);
Query OK, 0 rows affected (0.01 sec)
mysql>
INSERT INTO t SET i = 1 / 0;
Query OK, 1 row affected (0.00 sec)
mysql>
SELECT i FROM t;
+------+
| i
|
+------+
| NULL |
+------+
1 row in set (0.00 sec)
As of MySQL 5.0.2, division by zero is an error if the proper SQL modes are in effect:
mysql>
SET sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO';
Query OK, 0 rows affected (0.00 sec)
mysql>
CREATE TABLE t (i TINYINT);
Query OK, 0 rows affected (0.00 sec)
mysql>
INSERT INTO t SET i = 1 / 0;
ERROR 1365 (22012): Division by 0
mysql>
SELECT i FROM t;
Empty set (0.01 sec)
Example 6. Exact-value literals are evaluated as exact values.
Prior to MySQL 5.0.3, exact-value and approximate-value literals both are evaluated as double-
precision floating-point values:
mysql>
SELECT VERSION();
Precision Math Examples
ERROR_FOR_DIVISION_BY_ZERO
1008
[536]
set, division by zero

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents