0

In mysql update the number in the column that it would be 9 digits

for example:

658 were recorded, but must be 000000658, 
if 96258, this must be 000096258, front contributed to 0.

Thanks

vhadalgi
  • 7,027
  • 6
  • 38
  • 67

2 Answers2

2

I think you'll have to change the datatype from int to varchar(9). Just have your code add on the zero's before committing to your database.
Example in PHP:

$foo = "604";
while(strlen($foo) < 9)
{
    $foo = "0".$foo;
}

$foo now equals 000000604. All you would need to do is write a loop to pull from your database and commit back to it.

1

While creating column use this:

ALTER table `table` CHANGE `column` `column` VARCHAR(9);    

While inserting or updating data use this:

UPDATE table SET `column` = LPAD(`column`, 9, '0'); #pads everything
Ali
  • 5,021
  • 4
  • 26
  • 45