MySQL out of range value for decimal column

那年仲夏 提交于 2020-01-06 08:09:52

问题


After searching, I found plenty of out of range problems with people not knowing that the first digit, m, in decimal(m,n) is the total amount of digits. However, that is not my problem.

For the column in question I have the following:

Field | Type                   | Null | Key | Default | Extra
preco | decimal(50,2) unsigned | NO   |     | 0.00    |

The setting decimal(50,2) is way more than I really want or need. I really only want 10 digits total. Its a price, so anything over 100 million is probably ridiculous, so decimal(10,2) would probably be more appropriate. However, MySQL Is not accepting the following query:

INSERT INTO `produto` (`tipo_id`, `preco`, `qtd`, `opcao1`) VALUES (110, '77888555.43', '10', 'Azul')

I tried the query through CodeIgniter, phpMyAdmin and directly in the MySQL command line client. I also tried it without the quotes on the decimal value but I always get the same error:

"Out of range value for column 'preco' at row 2"


回答1:


I have tried it with SQLyog, it is working perfect. I tried to change both ways in SQLyog directly through Table Data tab and using Query. It is just working. it seems there is no problem in Decimal Range, but problem is some where else. See the screenshots attached

Directly through Table Data Tab

Through insert query

Table Structure

Hope it help...




回答2:


You are sending the value for preco as a string which is accepted by MySQL in the same way as a numerical value.



来源:https://stackoverflow.com/questions/12184539/mysql-out-of-range-value-for-decimal-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!