
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Values of a 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)
Advertisements