- 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
MySQL left padding with zeros separated by hyphen?
Let us first create a table −
mysql> create table DemoTable829(SerialNumber int); Query OK, 0 rows affected (0.64 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable829 values(100); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable829 values(101); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable829 values(102); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable829 values(103); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable829 values(104); Query OK, 1 row affected (0.60 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable829;
This will produce the following output −
+--------------+ | SerialNumber | +--------------+ | 100 | | 101 | | 102 | | 103 | | 104 | +--------------+ 5 rows in set (0.00 sec)
Following is the query to pad zeros separated by a hyphen −
mysql> select RIGHT(CONCAT('000-', SerialNumber), 7) from DemoTable829;
This will produce the following output −
+----------------------------------------+ | RIGHT(CONCAT('000-', SerialNumber), 7) | +----------------------------------------+ | 000-100 | | 000-101 | | 000-102 | | 000-103 | | 000-104 | +----------------------------------------+ 5 rows in set (0.00 sec)
- Related Articles
- REGEX in MySQL to display only numbers separated by hyphen.
- Finding the minimum and maximum value from a string with numbers separated by hyphen in MySQL?
- How to concatenate string vectors separated with hyphen in R?
- How to concatenate two column values into a single column with MySQL. The resultant column values should be separated by hyphen
- Combine values of two columns separated with hyphen in an R data frame.
- CSS padding-left property
- Specify the left padding of an element with CSS
- Animate CSS padding-left property
- Left pad an integer in Java with zeros
- Left pad a String in Java with zeros
- How to set the left padding of an element with JavaScript?
- Fetch substrings from a string with words separated by slash in MySQL?
- PHP preg_split with hyphen?
- Return the numeric string left-filled with zeros in Numpy
- MySQL select for exact case sensitive match with hyphen in records

Advertisements