Kiran Kumar
Kiran Kumar

Reputation: 177

Mysql Display four(4) digit numbers

In Mysql I want to display numbers using 4 digit patterns. example :

select 1    => result : 0001
select 2    => result : 0002
select 25   => result : 0025

How can I achieve this?

Upvotes: 1

Views: 1810

Answers (2)

Fahmi
Fahmi

Reputation: 37473

Try using lpad() function

demo

SELECT LPAD(columnanme, 4,'0');

Output:

LPAD('11', 4,'0')
0011

Upvotes: 2

Mureinik
Mureinik

Reputation: 311393

You could use the lpad function to pad zeroes to the left of the result:

SELECT LPAD(mycol, 4, '0')
FROM   mytable

Upvotes: 5

Related Questions