开发者

How can I pad a number with zeros in MySQL?

I want to execute this kind of a query:

SELECT 00005

Now its r开发者_如何学运维esult showing as 5. It not taking '0000'. How to get the correct value. Any body can help me.


00005 is not a number, but it is a string...

SELECT '00005'


You can use the LPAD function:

SELECT LPAD(5, 5, 0)


You can set a ZEROFILL property, e.g. -

CREATE TABLE table1(
  column1 INT(5) UNSIGNED ZEROFILL DEFAULT NULL
);

SELECT * FROM table1;
+---------+
| column1 |
+---------+
|   00005 |
|   00025 |
+---------+
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜