Home > Database > Mysql Tutorial > body text

How does MySQL CAST handle overflow?

WBOY
Release: 2023-09-07 22:17:11
forward
946 people have browsed it

MySQL CAST 如何处理溢出?

#MySQL CAST can handle overflows that occur during the evaluation of numeric expressions. Suppose that if a numeric expression evaluation produces an overflow, MySQL will reflect an error message. Now to handle this overflow we can change the value to UNSIGNED with the help of CAST.

For example, when adding 1 to the maximum value of BIGINT, MySQL generates an error due to overflow as shown below -

mysql> Select 9223372036854775807 + 1;
ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807+1)'
Copy after login

Now, with the help of CAST, MySQL handles this as follows Overflow:

mysql> Select CAST(9223372036854775807 AS UNSIGNED) +1;

+------------------------------------------+
| CAST(9223372036854775807 AS UNSIGNED) +1 |
+------------------------------------------+
| 9223372036854775808                      |
+------------------------------------------+
1 row in set (0.07 sec)
Copy after login

The above is the detailed content of How does MySQL CAST handle overflow?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template