且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-12-01 11:36:10

在列上声明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