开发者

How can I pad a number with zeros in MySQL?

开发者 https://www.devze.com 2023-03-25 02:30 出处:网络
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,

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

精彩评论

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