长整数在插入较短的列时被转换,而不是被截断.为什么?公式是什么? [英] Long integer is transformed when inserted in shorter column, not truncated. Why? What is the formula?
问题描述
我有一列长度为 10 的 integer
类型:
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 715988985123857
turn 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
整数溢出会将数据库中的最大允许数设置为
The integer overflow will set the max allowed number in the DB as
2147483647
所以你需要 bigint
数据类型来存储更大的整数
So you need bigint
datatype for storing bigger integer
这篇关于长整数在插入较短的列时被转换,而不是被截断.为什么?公式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!