我想知道是否有一种方法可以在选择时将前导零添加到少于4个字符的数字并转换为字符串。
我感谢任何建议,提前谢谢!
类似的东西:
SELECT PAD(CAST(last4 as string), 4) as last4 from numbers
期望的输出:
1 => 0001
100 => 0100
112 => 0112
15 => 0015
答案 0 :(得分:2)
你离我很近:
SELECT LPAD(last4, 4, '0') as last4 FROM numbers;
请参阅https://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_lpad