MySQL 错误 1264 (22003):列值超出范围
MySQL ERROR 1264 (22003): Out of range value for column
我收到这个错误:
ERROR 1264 (22003): Out of range value for column 'median_comments' at
row 1
在 运行 这个查询之后:
update influencers set `median_comments` = 1347 WHERE `id` = 1;
我不确定为什么在这个没有任何小数且只有 4 位数字的数字上失败。
字段类型为:
median_comments decimal(10,8)
您正在使用 DECIMAL(10,8)
,这意味着小数点前的最大位数为 (10 - 8) = 2
。
参考:DECIMAL Data Type Characteristics
The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments are as follows:
- M is the maximum number of digits (the precision). It has a range of 1 to 65.
- D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.
要修复错误,请将您的数据类型更改为 DECIMAL(10,2)
。
ALTER TABLE `influencers`
CHANGE COLUMN `median_comments` `median_comments` DECIMAL(10,2) NOT NULL DEFAULT 0;
如果您使用 decimal(10,8) 作为数据类型,这意味着您在小数点后指定了 8 位数字,这样您的整数只剩下(10 - 8,即 2 位数字)。
在这种情况下,由于您的号码 1347 包含 4 位数字(整数),因此您会收到“超出范围值”的错误,因为您只能输入 2。
您应该考虑将其至少更改为小数 (12,8),这将为您的整数部分留出 4 位数字,并且您的上述命令应该有效。
请参考post - 。同样的问题。
我收到这个错误:
ERROR 1264 (22003): Out of range value for column 'median_comments' at row 1
在 运行 这个查询之后:
update influencers set `median_comments` = 1347 WHERE `id` = 1;
我不确定为什么在这个没有任何小数且只有 4 位数字的数字上失败。
字段类型为:
median_comments decimal(10,8)
您正在使用 DECIMAL(10,8)
,这意味着小数点前的最大位数为 (10 - 8) = 2
。
参考:DECIMAL Data Type Characteristics
The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments are as follows:
- M is the maximum number of digits (the precision). It has a range of 1 to 65.
- D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.
要修复错误,请将您的数据类型更改为 DECIMAL(10,2)
。
ALTER TABLE `influencers`
CHANGE COLUMN `median_comments` `median_comments` DECIMAL(10,2) NOT NULL DEFAULT 0;
如果您使用 decimal(10,8) 作为数据类型,这意味着您在小数点后指定了 8 位数字,这样您的整数只剩下(10 - 8,即 2 位数字)。
在这种情况下,由于您的号码 1347 包含 4 位数字(整数),因此您会收到“超出范围值”的错误,因为您只能输入 2。
您应该考虑将其至少更改为小数 (12,8),这将为您的整数部分留出 4 位数字,并且您的上述命令应该有效。
请参考post -