- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do you fill in or pad a column with zeros using a MySQL query?
You can use ZEROFILL for column to fill in or pad with zeros. Let us first create a table−
mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.58 sec)
Following is the query to add zerofill attribute for Number column−
mysql> alter table DemoTable change Number Number int(10) zerofill not null; Query OK, 0 rows affected (1.13 sec) Records: 0 Duplicates: 0 Warnings: 0
Insert records in the table using insert command −
mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(12); Query OK, 1 row affected (0.53 sec) mysql> insert into DemoTable values(123); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1234); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(12345); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output−
+------------+ | Number | +------------+ | 0000000001 | | 0000000012 | | 0000000123 | | 0000001234 | | 0000012345 | +------------+ 5 rows in set (0.00 sec)
- Related Articles
- Pad the values of the column with zeros in MySQL
- How to pad a number with leading zeros in JavaScript?
- Left pad a String in Java with zeros
- How do I insert multiple values in a column with a single MySQL query?
- Left pad an integer in Java with zeros
- How do you separate zeros from non-zeros in an integer array using Java?
- How do you get whether a column is a primary key in MySQL?
- MySQL number-string formatting to pad zeros on the left of a string with numbers after a slash
- Pad the displayed value of the field with zeros up to the display width specified in the column definition in MySQL?
- In MySQL, how can we pad a string with another string?
- Add leading zeros to a MySQL column?
- Fetch a specific record using a single MySQL query with AND & OR operator
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- How to change format of dates in a table column with a MySQL query?
- How do I check if a column is empty or null in MySQL?

Advertisements