mysql的decimal长度之坑------Out of range value for column xxx

        踩了个坑, 来看看:

CREATE TABLE x (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    cost DECIMAL(2, 1) NOT NULL
);

        然后:

mysql> INSERT INTO x(cost)VALUES(1.3);
Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO x(cost)VALUES(10.3);
ERROR 1264 (22003): Out of range value for column 'cost' at row 1
mysql> 

       注意, DECIMAL(2, 1)的格式, 和C语言中printf控制长度的格式类似。

       2是总长度, 额, 呵呵哒。

       

       没什么好说的。

       不多说。

发布了2213 篇原创文章 · 获赞 4564 · 访问量 1977万+

猜你喜欢

转载自blog.csdn.net/stpeace/article/details/101097299
今日推荐