Home  >  Article  >  Database  >  What is the use of ZEROFILL for INT data type?

What is the use of ZEROFILL for INT data type?

王林
王林forward
2023-08-24 09:05:05907browse

What is the use of ZEROFILL for INT data type?

When you specify ZEROFILL for a numeric column, MYSQL automatically pads zeros in front of the field's display value until the display width specified in the column definition is reached.

For example, we create a table named showzerofill and insert the following value:

mysql> Create Table showzerofill(Val1 INT(5) ZEROFILL, Val2 INT(5));
Query OK, 0 rows affected (0.09 sec)

mysql> Insert into showzerofill(Val1, Val2)
values(1,1>,<12,12>,<123,123>,<1234,1234>,<12345,12345>;
Query OK, 5 rows affected (0.03 sec)
Records: 5 Duplicates: 0 Warnings: 0

Now we can easily understand the impact of ZEROFILL on the value of column Val1.

ZEROFILL pads numbers with zeros until the display width specified in the column definition is reached.

mysql> Select * from showzerofill;
+-------+-------+
| Val1  | Val2  |
+-------+-------+
| 00001 |     1 |
| 00012 |    12 |
| 00123 |   123 |
| 01234 |  1234 |
| 12345 | 12345 |
+-------+-------+
5 rows in set (0.00 sec)

In this sense, we can say that if we want to display the values ​​of a column with a specific width, then we can define that column using ZEROFILL.

The above is the detailed content of What is the use of ZEROFILL for INT data type?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete