使用 MySQL 中的 zerofill 的好處是什麼?
ZEROFILL 用零填充欄位的顯示值,直至達到列定義中設定的顯示寬度。讓我們透過一個示例來了解 zero fill 在 MySQL 中的作用。建立一個有兩列的表,一列使用 zerofill,另一列不使用。用於建立表的查詢。
mysql> create table ZeroFillDemo -> ( -> First int(18) zerofill, -> Second int(18) -> ); Query OK, 0 rows affected (0.63 sec)
我們可以使用 INSERT 命令在表中插入記錄。查詢如下。
mysql> insert into ZeroFillDemo values(1,1); Query OK, 1 row affected (0.13 sec) mysql> insert into ZeroFillDemo values(12,12); Query OK, 1 row affected (0.15 sec) mysql> insert into ZeroFillDemo values(123,123); Query OK, 1 row affected (0.10 sec) mysql> insert into ZeroFillDemo values(123456789,123456789); Query OK, 1 row affected (0.20 sec)
現在,我們可以藉助 select 命令來檢視 zerofill 列的好處。
查詢如下。
mysql> select *from ZeroFillDemo;
以下是輸出。
+--------------------+-----------+ | First | Second | +--------------------+-----------+ | 000000000000000001 | 1 | | 000000000000000012 | 12 | | 000000000000000123 | 123 | | 000000000123456789 | 123456789 | +--------------------+-----------+ 4 rows in set (0.00 sec)
檢視示例輸出,將在開頭填充零。
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP