2

I have a profile database, and I have selected a column of int(10) to store the phone number. So when I enter the 10 digit phone number, it returns a warning #1264, saying the value is out of range.

I increased the int(250) but I still get the same error. Why??!

Thanks

user2133369
  • 31
  • 1
  • 3
  • 2
    This message is a duplicate of http://stackoverflow.com/questions/6921613/mysql-int11-number-out-of-range – AbsoluteƵERØ Jun 15 '13 at 02:33
  • If you don't show us what you are doing to "enter the 10-digit phone number", how can we possibly tell you what you're doing wrong? You need to [edit] your question and provide more information. It's important here to be specific if you want us to help you. – Ken White Jun 15 '13 at 02:34
  • possible duplicate of [How do I fix the 'Out of range value adjusted for column' error?](http://stackoverflow.com/questions/1786509/how-do-i-fix-the-out-of-range-value-adjusted-for-column-error) – Brad Werth Sep 16 '14 at 16:27

3 Answers3

3

You are storing a phone as an integer, which has an upper limit. The maximum value for 32-bit signed integers is 2147483647, so if your phone number is larger than that, you'll get an out of range warning. I'd suggest to change your field to a VARCHAR with a size of 10, as an integer isn't a good field type to represent phone numbers.

Filippos Karapetis
  • 4,367
  • 21
  • 39
2

The largest value for an int field is 2147483647. Make it a BIGINT, or use a VARCHAR field if you need even bigger values. It is quite common to use a textual fields (varchar) for phone numbers anyway.

See: http://dev.mysql.com/doc/refman/5.0/en/integer-types.html

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
0
I increased the int(250) …

No you didn't: for all integer types, that value does not increase the field size – only the display width if the field also has the ZEROFILL flag.


CREATE TABLE `ints` (
  `tinyint1` tinyint(1) unsigned zerofill DEFAULT NULL,
  `tinyint4` tinyint(4) unsigned zerofill DEFAULT NULL,
  `int11` int(11) unsigned zerofill DEFAULT NULL,
  `bigint30` bigint(30) unsigned zerofill DEFAULT NULL
);

INSERT INTO ints VALUES (1, 1, 1, 1);
INSERT INTO ints VALUES (5, 5, 5, 5);
INSERT INTO ints VALUES (10, 10, 10, 10);
INSERT INTO ints VALUES (100, 100, 100, 100);

INSERT INTO ints VALUES (10212072467628961, 10212072467628961, 10212072467628961, 10212072467628961);
ERROR 1264 (22003): Out of range value for column 'tinyint1' at row 1

INSERT INTO ints VALUES (0, 0, 0, 10212072467628961);

SELECT * FROM ints;
+----------+----------+-------------+--------------------------------+
| tinyint1 | tinyint4 | int11       | bigint30                       |
+----------+----------+-------------+--------------------------------+
|        1 |     0001 | 00000000001 | 000000000000000000000000000001 |
|        5 |     0005 | 00000000005 | 000000000000000000000000000005 |
|       10 |     0010 | 00000000010 | 000000000000000000000000000010 |
|      100 |     0100 | 00000000100 | 000000000000000000000000000100 |
|        0 |     0000 | 00000000000 | 000000000000010212072467628961 |
+----------+----------+-------------+--------------------------------+
5 rows in set (0.01 sec)

As the other guys have suggested, you have to use a different integer type:

http://dev.mysql.com/doc/refman/5.0/en/integer-types.html


The only way to "increase" the effective range is by using the UNSIGNED flag and omitting all negative values – but that's technically a shifting of the range, not an increase. Technically.

WoodrowShigeru
  • 1,418
  • 1
  • 18
  • 25