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 9223372036857775807233720368577758072337203685 775
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:
#MySQL enables such kind of operations by converting the values to signed as foluns −
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 如何處理數值表達式評估期間的溢位?的詳細內容。更多資訊請關注PHP中文網其他相關文章!