Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code DEF204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

Rechercher dans le manuel MySQL

11.2.6 Out-of-Range and Overflow Handling

When MySQL stores a value in a numeric column that is outside the permissible range of the column data type, the result depends on the SQL mode in effect at the time:

  • If strict SQL mode is enabled, MySQL rejects the out-of-range value with an error, and the insert fails, in accordance with the SQL standard.

  • If no restrictive modes are enabled, MySQL clips the value to the appropriate endpoint of the column data type range and stores the resulting value instead.

    When an out-of-range value is assigned to an integer column, MySQL stores the value representing the corresponding endpoint of the column data type range.

    When a floating-point or fixed-point column is assigned a value that exceeds the range implied by the specified (or default) precision and scale, MySQL stores the value representing the corresponding endpoint of that range.

Suppose that a table t1 has this definition:

With strict SQL mode enabled, an out of range error occurs:

  1. mysql> SET sql_mode = 'TRADITIONAL';
  2. mysql> INSERT INTO t1 (i1, i2) VALUES(256, 256);
  3. ERROR 1264 (22003): Out of range value for column 'i1' at row 1
  4. mysql> SELECT * FROM t1;
  5. Empty set (0.00 sec)

With strict SQL mode not enabled, clipping with warnings occurs:

  1. mysql> SET sql_mode = '';
  2. mysql> INSERT INTO t1 (i1, i2) VALUES(256, 256);
  3. mysql> SHOW WARNINGS;
  4. +---------+------+---------------------------------------------+
  5. | Level   | Code | Message                                     |
  6. +---------+------+---------------------------------------------+
  7. | Warning | 1264 | Out of range value for column 'i1' at row 1 |
  8. | Warning | 1264 | Out of range value for column 'i2' at row 1 |
  9. +---------+------+---------------------------------------------+
  10. mysql> SELECT * FROM t1;
  11. +------+------+
  12. | i1   | i2   |
  13. +------+------+
  14. |  127 |  255 |
  15. +------+------+

When strict SQL mode is not enabled, column-assignment conversions that occur due to clipping are reported as warnings for ALTER TABLE, LOAD DATA, UPDATE, and multiple-row INSERT statements. In strict mode, these statements fail, and some or all the values are not inserted or changed, depending on whether the table is a transactional table and other factors. For details, see Section 5.1.11, “Server SQL Modes”.

Overflow during numeric expression evaluation results in an error. For example, the largest signed BIGINT value is 9223372036854775807, so the following expression produces an error:

  1. mysql> SELECT 9223372036854775807 + 1;
  2. ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807 + 1)'

To enable the operation to succeed in this case, convert the value to unsigned;

  1. mysql> SELECT CAST(9223372036854775807 AS UNSIGNED) + 1;
  2. +-------------------------------------------+
  3. | CAST(9223372036854775807 AS UNSIGNED) + 1 |
  4. +-------------------------------------------+
  5. |                       9223372036854775808 |
  6. +-------------------------------------------+

Whether overflow occurs depends on the range of the operands, so another way to handle the preceding expression is to use exact-value arithmetic because DECIMAL values have a larger range than integers:

  1. mysql> SELECT 9223372036854775807.0 + 1;
  2. +---------------------------+
  3. | 9223372036854775807.0 + 1 |
  4. +---------------------------+
  5. |     9223372036854775808.0 |
  6. +---------------------------+

Subtraction between integer values, where one is of type UNSIGNED, produces an unsigned result by default. If the result would otherwise have been negative, an error results:

  1. mysql> SET sql_mode = '';
  2. Query OK, 0 rows affected (0.00 sec)
  3.  
  4. mysql> SELECT CAST(0 AS UNSIGNED) - 1;
  5. ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(cast(0 as unsigned) - 1)'

If the NO_UNSIGNED_SUBTRACTION SQL mode is enabled, the result is negative:

  1. mysql> SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';
  2. mysql> SELECT CAST(0 AS UNSIGNED) - 1;
  3. +-------------------------+
  4. | CAST(0 AS UNSIGNED) - 1 |
  5. +-------------------------+
  6. |                      -1 |
  7. +-------------------------+

If the result of such an operation is used to update an UNSIGNED integer column, the result is clipped to the maximum value for the column type, or clipped to 0 if NO_UNSIGNED_SUBTRACTION is enabled. If strict SQL mode is enabled, an error occurs and the column remains unchanged.


Suchen Sie im MySQL-Handbuch

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 26/06/2006, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/mysql-rf-out-of-range-and-overflow.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:en Manuel MySQL : https://dev.mysql.com/

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut