Long integer is transformed when inserted in shorter column, not truncated. Why? What is the formula?(长整数在插入较短的列时进行转换,而不是截断.为什么?公式是什么?)
问题描述
我有一列 integer 类型的列,长度为 10:
I have a column of type integer with length 10:
`some_number` int(10) unsigned NOT NULL
我在此列中插入了一个太长的数字:
Into this column I insert a number that is too long:
$some_number = 715988985123857;
$query = "INSERT INTO this_table SET some_number = ?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('i', $some_number);
$stmt->execute();
当我查看表格中的内容时,现在的数字是:
When I look at what is in the table, the number is now:
2147483647
715988985123857如何以及为什么变成2147483647?
为什么它没有被截断?
这种转换背后的机制是什么,可以用一些公式计算得到的数字吗?
How and why did 715988985123857turn into 2147483647?
Why didn't it get truncated?
What is the mechanism behind this transformation, and can the resulting number be calculated with some formula?
我不是在寻找解决方案.我只是想了解具体的数字.
I'm not looking for a solution. I just want to understand the specific number.
推荐答案
http://dev.mysql.com/doc/refman/5.0/en/integer-types.html
整数溢出会将DB中的最大允许数设置为
The integer overflow will set the max allowed number in the DB as
2147483647
所以你需要 bigint 数据类型来存储更大的整数
So you need bigint datatype for storing bigger integer
这篇关于长整数在插入较短的列时进行转换,而不是截断.为什么?公式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:长整数在插入较短的列时进行转换,而不是截断.为什么?公式是什么?
基础教程推荐
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php中的PDF导出 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- php中的foreach复选框POST 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
