RedHawkDK
RedHawkDK

Reputation: 139

mysql store +90 digits number starting with zero

I need to store a number with +90 digits in my mysqldatabase.

I can't figure out what type of the table should be, and if some other attributes should be applied.

An example number: 00004219087128907490128309172409712089378174801278903710874y8012780731

It is important, that the leading zeros remain in the database.

Thanks in advance !

Upvotes: 1

Views: 482

Answers (3)

Ravinder Reddy
Ravinder Reddy

Reputation: 24012

You need a varchar datatype to store the lengthy numeric - string.

But you should know that it the SQL statement needs to follow string specific syntax. That is, surround any value, either numeric, date, or others in single quotes. 'num or date here'. So that the value is treated as a string.

In your case, you seem to input 000011 number as is without quotes. And hence MySQL implicitly interpreted it as a number and removed leading zeros.

mysql> select 000011, '000011';
+--------+--------+
| 000011 | 000011 |
+--------+--------+
|     11 | 000011 |
+--------+--------+
1 row in set (0.00 sec)

Following INSERT example should also help you.

mysql> insert into vc_num( vn ) values (000011), ( '000011' );
Query OK, 2 rows affected (0.08 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from vc_num;
+--------+
| vn     |
+--------+
| 11     |
| 000011 |
+--------+

Upvotes: 0

Nagaraj S
Nagaraj S

Reputation: 13484

set your column datatype as varchar(100)

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used

Upvotes: 1

oldhomemovie
oldhomemovie

Reputation: 15129

Use varchar(90) as a type for that field.

Example of table definition (for MySQL):

CREATE TABLE myTable (
  id int auto_increment primary key, 
  my_big_number varchar(90)
);

Upvotes: 0

Related Questions