当前位置:Gxlcms >
数据库问题 >
MySQL BIGINT UNSIGNED value is out of range... 的问题和解决
MySQL BIGINT UNSIGNED value is out of range... 的问题和解决
时间:2021-07-01 10:21:17
帮助过:39人阅读
从MySQL 5.5.5开始,这种情况会返回一个错误:BIGINT UNSIGNED value is out of range...
比如:
如果结果为负数:
[SQL] SELECT (CAST(0 AS UNSIGNED)-1);
[
Err] 1690 - BIGINT UNSIGNED value is out of range in ‘(cast(0 as unsigned) - 1)‘
[SQL] SELECT (1-CAST(2 AS UNSIGNED));
[
Err] 1690 - BIGINT UNSIGNED value is out of range in ‘(1 - cast(2 as unsigned))‘
如果结果为正数:
[SQL]
SELECT (1-CAST(0 AS UNSIGNED));
1
解决方法:
1、如果确实可以接受负数的结果,那么把其中的UNSIGNED
字段强转为SIGNED类型:
[SQL] SELECT (1-CAST(2 AS
SIGNED));
-1
如果计算结果是要插入到另外一个UNSIGNED INT字段中的话,那么就不要强转了,直接捕捉并报告异常。
参考:http://dev.mysql.com/doc/refman/5.6/en/out-of-range-and-overflow.html
(原创文章,转载请注明转自Clement-Xu的博客)
版权声明:本文为原创文章,转载请注明转自Clement-Xu的csdn博客。
MySQL BIGINT UNSIGNED value is out of range... 的问题和解决
标签:mysql bigint outofrange