在mysql中更新列中的数字,它将是9位
例如:
658 were recorded, but must be 000000658,
if 96258, this must be 000096258, front contributed to 0.
谢谢
答案 0 :(得分:2)
我认为您必须将数据类型从int更改为varchar(9)。在提交到数据库之前,只需将代码添加到零上即可 PHP中的示例:
$foo = "604";
while(strlen($foo) < 9)
{
$foo = "0".$foo;
}
$ foo现在等于000000604.您需要做的就是编写一个循环来从数据库中提取并提交回来。
答案 1 :(得分:1)
创建列时使用:
ALTER table `table` CHANGE `column` `column` VARCHAR(9);
插入或更新数据时请使用:
UPDATE table SET `column` = LPAD(`column`, 9, '0'); #pads everything