如何給 MySQL 表格值追加 000?


若要追加 000,請使用 ZEROFILL 的概念。我們先建立一個表 -

mysql> create table DemoTable1913
   (
   Code int(4) ZEROFILL AUTO_INCREMENT NOT NULL,
   PRIMARY KEY(Code)
   );
Query OK, 0 rows affected (0.00 sec)

使用 insert 命令在表中插入一些記錄 -

mysql> insert into DemoTable1913 values(1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1913 values(2);
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1913 values(3);
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1913 values(4);
Query OK, 1 row affected (0.00 sec)

使用 select 語句顯示錶中的所有記錄 -

mysql> select * from DemoTable1913;

這將生成以下輸出 -

+------+
| Code |
+------+
| 0001 |
| 0002 |
| 0003 |
| 0004 |
+------+
4 rows in set (0.00 sec)

更新於:30-12-2019

159 檢視次數

開啟你的 職業 生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.