gpt4 book ai didi

mysql - 警告#1264 :out of range error in mysql

转载 作者:IT王子 更新时间:2023-10-29 00:31:02 26 4
gpt4 key购买 nike

以下查询:

INSERT INTO skill (`emp_number`, `skill_id`, `year_exp`, `comments`)
VALUES ('4', '3', '23.45', '')

它正在产生错误:

1 row inserted.
Warning: #1264 Out of range value for column 'year_exp' at row 1
year_exp column is of datatype decimal(2,2)

请帮我找出错误。

最佳答案

我认为您遇到此错误是因为 year_exp 字段是 DECIMAL(2,2),而您需要 DECIMAL(4,2)DECIMAL(2,2) 表示精度为 2 的数字,最多保留 2 位小数。但是这个数字有 4 位精度。

这个指向 MSDN 的链接讨论了小数精度。

http://msdn.microsoft.com/en-US/library/ms187746(v=SQL.90).aspx

这是一个具有类似结果的快速测试(在 SQL Server 2008 中完成,但我认为您使用的是 MySQL...)

1) 创建一个带有测试列的表:

CREATE TABLE testtable (testcolumn DECIMAL(2,2))

2) 运行插入语句...:

INSERT INTO testtable (testcolumn) VALUES (23.45)

...并收到此错误...

Msg 8115, Level 16, State 8, Line 1
Arithmetic overflow error converting numeric to data type numeric.

(评论:我最喜欢的错误之一......“无法将数字转换为数字......”哈哈)

3) 将列更改为适当的规范

ALTER TABLE testtable ALTER COLUMN testcolumn DECIMAL(4,2)

4) 重新运行相同的插入语句。有用。

如果这有帮助,请告诉我。

关于mysql - 警告#1264 :out of range error in mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14216642/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com