php Mysql int(11) 数字超出范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6921613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql int(11) number out of range
提问by maxum
I have a column which is set to int(20)
when I try and insert a number like 622108120237
, it says it's out of range. Why?
我有一个列,int(20)
当我尝试插入一个数字时设置为622108120237
,它说它超出范围。为什么?
回答by Pascal MARTIN
An int
, with MySQL, is stored on 4 bytes, and, as such, can only contain values between -2147483648
and 2147483647
.
在int
MySQL 中,一个 存储在 4 个字节上,因此,只能包含-2147483648
和之间的值2147483647
。
622108120237
is greater than 2147483647
; so it doesn't fit into an int
-- looks like you are going to have to use a bigint
.
622108120237
大于2147483647
; 所以它不适合int
- 看起来你将不得不使用bigint
.
See the Datatypes - Numeric typessection of
the MySQL manual, about that.
请参阅MySQL 手册的数据类型 - 数字类型部分
,了解相关内容。
回答by Pascal MARTIN
See the MySQL Numeric Type Documentation. These things are well-documented.
请参阅 MySQL 数字类型文档。这些事情有据可查。
The range for a signed INT
is [-2147483648, 2147483647].
有符号的范围INT
是 [-2147483648, 2147483647]。
Note that in the case of INT(x)
, x is the "display width"and has nothing to do with the range or space requirements:
请注意,在 的情况下INT(x)
,x 是“显示宽度”,与范围或空间要求无关:
MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits ... display width does not constrain [or expand] the range of values that can be stored in the column.
MySQL 支持一个扩展,用于在类型的 base 关键字后面的括号中选择性地指定整数数据类型的显示宽度。例如,INT(4) 指定显示宽度为四位数的 INT……显示宽度不限制 [或扩展] 列中可以存储的值的范围。
Happy coding.
快乐编码。
回答by nidhin
The maximum value you can store in an signed integer is 2147483647 And unsigned int is 4294967295 in Both case you exceed the limit
您可以存储在有符号整数中的最大值是 2147483647 并且 unsigned int 是 4294967295 在这两种情况下都超过了限制