MySQL将前导数字添加到列中的现有ID

1 mysql phpmyadmin sql-update

我有一个名为country_id的mysql数据库列,如:

country_id
----------
1
2
59
435
2714
Run Code Online (Sandbox Code Playgroud)

我现在想要完成的是为每个ID添加前导零,所以结果将是:

country_id
----------
0001
0002
0059
0435
2714
Run Code Online (Sandbox Code Playgroud)

每个ID最多应有4位数字.而已.

我是否可以在PHPmyAdmin中使用任何SQL语句以上述方式更新此country_id列?

最好的祝福!

Wri*_*ken 5

ZEROFILL在列上声明:

mysql> create table foobar (nr integer(4) ZEROFILL);
Query OK, 0 rows affected (0.31 sec)

mysql> INSERT INTO foobar VALUES (1),(12),(123),(1234),(12345);
Query OK, 5 rows affected (0.05 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM foobar;
|  0001 
|  0012 
|  0123 
|  1234 
| 12345 
Run Code Online (Sandbox Code Playgroud)