Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Out of range value for column 'contact_no' at row 1

Tags:

sql

mysql

I was trying to add a number with a length of 11 but when I input it in the database it can't. If I try to add a number with a length of 10 it can.

This is the error:

ERROR 1264: 1264: Out of range value for column 'contact_no' at row 1
SQL Statement:
INSERT INTO `mcs`.`new_table` (`id`, `contact_no`) VALUES ('1', '12345678901')
like image 528
Kaye Santos Avatar asked Mar 18 '23 07:03

Kaye Santos


2 Answers

It's not clear what question you are asking.

Why is this error being returned?

Likely, the contact_no column is declared with datatype of INT, a 32-bit integer, and you attempted to assign a value larger than the supported maximum value.

The maximum value for a signed 32-bit integer is 2,147,483,647. (that decimal value of 2^31-1. For an unsigned 32-bit integer, maximum value is 2^32.)

Some other question that wasn't asked

If you need to store values larger than the maximum supported by the INT datatype, you could define the column as a different datatype.

For example, BIGINT gives a maximum value of 2^63-1 for unsigned.

If you need a maximum of 12 decimal digits, you could use a DECIMAL(12) datatype.

like image 177
spencer7593 Avatar answered Mar 23 '23 21:03

spencer7593


Change your data type of contact_no to BIGINT.
Check range of different data type at MYSQL official website.
I personally recommend you to use varchar, as you don't need to compare contact number with any field.

like image 34
unknown Avatar answered Mar 23 '23 21:03

unknown