我有一个名为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列?
最好的祝福!
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)
| 归档时间: |
|
| 查看次数: |
7055 次 |
| 最近记录: |