声明x bigint;设置x= 180181182149150151152;
错误:列'x‘在第1行超出范围值。
所以我的问题是,我能在bigint里面存储一个像上面这样的大数字吗?
发布于 2020-05-25 16:13:27
下面是BIGINT UNSIGNED支持的最大值,与您使用的数字相比:
180181182149150151152 = your number
18446744073709551615 = 2^64-1, largest value for BIGINT UNSIGNED您可以看到,您的数字比MySQL支持的最大整数值大10倍。您的数字需要68位才能存储,但是MySQL只支持不超过64位的整数数据类型。
您可以在FLOAT或DOUBLE中存储更大的值,但是您将失去精度。换句话说,你根本无法将68位信息放入64位编码中。
mysql> create procedure p() begin declare x double; set x = 180181182149150151152; select x; end;;
mysql> call p;;
+-----------------------+
| x |
+-----------------------+
| 1.8018118214915015e20 |
+-----------------------+如果给出足够的精度,可以使用DECIMAL():
mysql> create procedure p() begin declare x decimal(64,0); set x = 180181182149150151152; select x; end;;
mysql> call p;;
+-----------------------+
| x |
+-----------------------+
| 180181182149150151152 |
+-----------------------+阅读更多:https://dev.mysql.com/doc/refman/8.0/en/fixed-point-types.html
https://stackoverflow.com/questions/62006258
复制相似问题