- 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
Pad the values of the column with zeros in MySQL
For this, use the concept of ZEROFILL. It pads the displayed value of the field with zeros up to the display width set in the column definition
Let us first create a table −
mysql> create table DemoTable626 (Value int(5) zerofill); Query OK, 0 rows affected (0.71 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable626 values(9); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable626 values(12); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable626 values(567); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable626 values(3478); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable626;
This will produce the following output −
+-------+ | Value | +-------+ | 00009 | | 00012 | | 00567 | | 03478 | +-------+ 4 rows in set (0.00 sec)
- Related Articles
- Pad the displayed value of the field with zeros up to the display width specified in the column definition in MySQL?
- How do you fill in or pad a column with zeros using a MySQL query?
- Left pad an integer in Java with zeros
- Left pad a String in Java with zeros
- MySQL number-string formatting to pad zeros on the left of a string with numbers after a slash
- How to pad a number with leading zeros in JavaScript?
- Match column values on the basis of the other two column values in MySQL
- Shuffling column values with MySQL?
- Get count of zeros for columns values declared with INT type in MySQL
- Select and insert values with preceding zeros in a MySQL table
- Get the maximum count of distinct values in a separate column with MySQL
- Can I get the count of repeated values in a column with MySQL?
- Concatenate rows on the basis of boolean values in another column with MySQL
- How to update multiple rows and left pad values in MySQL?
- Get all the records with two different values in another column with MySQL

Advertisements