Come produrre questa eccezione sulla console di MySQL:
mysql> create table penguin (mydecimal decimal(9,8));
Query OK, 0 rows affected (0.02 sec)
mysql> insert into penguin values (1234.1234);
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> show warnings;
+---------+------+----------------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------------+
| Warning | 1264 | Out of range value for column 'mydecimal' at row 1 |
+---------+------+----------------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from penguin;
+------------+
| mydecimal |
+------------+
| 9.99999999 |
+------------+
1 row in set (0.00 sec)
Si è cercato di stipare 1234 in una colonna che potrebbe trarre il massimo 9.9 ripetuto. Si noti che la riga è ancora inserita.
È possibile ottenere la console di MySQL per evitare che questa conversione utilizzando la modalità rigorosa:
mysql> set sql_mode=STRICT_ALL_TABLES;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into penguin values (5678.5678);
ERROR 1264 (22003): Out of range value for column 'mydecimal' at row 1
L'inserto comando non è riuscito nel tentativo aggiungere una seconda fila al pinguino:
mysql> select * from penguin;
+------------+
| mydecimal |
+------------+
| 9.99999999 |
+------------+
1 row in set (0.00 sec)
Solutions
- Espandi la dimensione del tipo di dati nella colonna per accettare il valore inserito.
- Riduci le dimensioni del valore che stai cercando di racchiudere in un piccolo tipo di dati.
fonte
2014-01-13 00:19:06
vedi questa domanda http://stackoverflow.com/questions/73109/mysql-data-truncation-error –