您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

MySQL 如何处理数值表达式评估期间的溢出?

2024/3/22 7:12:54发布35次查看
as we know that mysql will produce an error if overflow occurs during the assessment of numeric expressions. for example, the largest signed bignt is 9223372036854775807, so the following expression will produce an error −
mysql> select 9223372036854775807 + 1;error 1690 (22003): bigint value is out of range in '(9223372036854775807+1)'
mysql can handle such kind of overflows in following ways:
by converting value to unsignedmysql enables such kind of operations by converting the values to unsigned as follows −
mysql> select cast(9223372036854775807 as unsigned) +1;+------------------------------------------+| cast(9223372036854775807 as unsigned) +1 |+------------------------------------------+| 9223372036854775808 |+------------------------------------------+1 row in set (0.07 sec)
通过使用精确值算术mysql可以使用精确值算术来处理上述表达式。这是因为溢出发生取决于操作数的范围。例如,可以通过使用decimal值来执行上述计算,如下所示−
mysql> select 9223372036854775807.0 + 1;+---------------------------+| 9223372036854775807.0 + 1 |+---------------------------+| 9223372036854775808.0 |+---------------------------+1 row in set (0.01 sec)
以上就是mysql 如何处理数值表达式评估期间的溢出?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product