MySQL out of range value for decimal column

2019-09-14 21:40发布

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"

2条回答
狗以群分
2楼-- · 2019-09-14 22:04

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

查看更多
聊天终结者
3楼-- · 2019-09-14 22:16

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 Directly through Table Data Tab

Through insert query Through insert query

Table Structureenter image description here

Hope it help...

查看更多
登录 后发表回答