Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

decimal - Warning#1264:out of range error in mysql

The following query:

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

It is producing the error :

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)

Please help me to pint out the error.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I believe you're having this error because the year_exp field is DECIMAL(2,2), and you want DECIMAL(4,2). DECIMAL(2,2) means a number of precision 2, with up to 2 decimal places. But this number has 4 digits of precision.

This link to MSDN talks about the decimal precision.

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

Here's a quick test with similar results (done in SQL Server 2008, but I think you're on MySQL...)

1) Created a table with a test column:

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

2) Ran insert statement... :

INSERT INTO testtable (testcolumn) VALUES (23.45)

... and received this error ...

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

(COMMENT: one of my fave errors ... "cannot convert number to number ..." ha ha)

3) Altered column to proper specifications

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

4) Re-ran same insert statement. It works.

Please let me know if this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...