简体   繁体   English

Mysql显示四(4)位数字

[英]Mysql Display four(4) digit numbers

In Mysql I want to display numbers using 4 digit patterns. 在Mysql中,我想使用4位数字模式显示数字。 example : 例如:

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

How can I achieve this? 我该如何实现?

You could use the lpad function to pad zeroes to the left of the result: 您可以使用lpad函数将零填充到结果的左侧:

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

Try using lpad() function 尝试使用lpad()函数

demo 演示

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

Output: 输出:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM