使用此命令:
mysql> insert into irctc_cap ( lid,amount,type) VALUES (296,-1000,128);
ERROR 1264 (22003): Out of range value for column 'amount' at row 1
Mysql版本:Ver 14.14 Distrib 5.7.19,
根据Warning#1264:out of range error in mysql,我看到不应出现此问题,因为length
的数量为12,4
答案 0 :(得分:1)
如果数据类型为DECIMAL(5,2)
,则表示五位数字总计,其中两位在小数点右边。因此,您可以使用的最大值是999.99,最小值是-999.99。这些是您最多可以输入的五位数。
如果您不使用严格模式,则会生成一条警告并将您尝试使用的值截断为五位数:
mysql> insert into irctc_cap values (296,-1000,128);
Query OK, 1 row affected, 1 warning (0.02 sec)
mysql> show warnings;
+---------+------+-------------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------------+
| Warning | 1264 | Out of range value for column 'amount' at row 1 |
+---------+------+-------------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from irctc_cap;
+------+---------+------+
| lid | amount | type |
+------+---------+------+
| 296 | -999.99 | 128 |
+------+---------+------+
如果使用严格模式,则警告将变为错误:
mysql> set sql_mode=strict_all_tables;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into irctc_cap values (296,-1000,128);
ERROR 1264 (22003): Out of range value for column 'amount' at row 1
我不确定为什么phpMyAdmin显示错误的数据类型。
使用DESCRIBE
或SHOW CREATE TABLE
或SELECT column_type FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='irctc_cap' AND COLUMN_NAME='amount'
获取列的准确定义。