Home > Database > Mysql Tutorial > body text

What is the use of ZEROFILL for INT data type?

王林
Release: 2023-08-24 09:05:05
forward
893 people have browsed it

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
Copy after login

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;
Copy after login
+-------+-------+
| Val1  | Val2  |
+-------+-------+
| 00001 |     1 |
| 00012 |    12 |
| 00123 |   123 |
| 01234 |  1234 |
| 12345 | 12345 |
+-------+-------+
5 rows in set (0.00 sec)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!