mysql BIGINT UNSIGNED
时间: 2023-10-12 14:08:06 浏览: 143
mysql unsigned 用法及相减出现补数溢出解决方法
MySQL中的BIGINT UNSIGNED是一种无符号的整数数据类型,使用8个字节(64位)来存储数据。它的取值范围是从0到18,446,744,073,709,551,615(2^64-1),也就是无符号64位整数的最大值。与普通的BIGINT类型不同,BIGINT UNSIGNED类型不能存储负数,因此适用于存储只有正整数的数据,如IP地址、端口号等。需要注意的是,在进行运算时,如果涉及到BIGINT UNSIGNED和BIGINT类型的混合运算,MySQL会将BIGINT UNSIGNED自动转换为BIGINT类型。
当使用BIGINT UNSIGNED类型进行相减运算时,如果结果是负数,在MySQL 5.5.5之前,结果会变成最大的整数(18446744073709551615)。而从MySQL 5.5.5开始,这种情况会返回一个错误:BIGINT UNSIGNED value is out of range。如果需要接受负数的结果,可以将其中的UNSIGNED字段强制转换为SIGNED类型。如果计算结果需要插入到另一个BIGINT UNSIGNED字段中,则应该直接捕获并报告异常。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [【小5聊】Mysql基础之bigint和bigint unsigned的区别](https://blog.csdn.net/lmy_520/article/details/122475907)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [MySQL BIGINT UNSIGNED value is out of range... 的问题和解决](https://blog.csdn.net/ClementAD/article/details/47280649)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文