有没有办法在DB2中存储为VARCHAR的数字之前填充0?
像这样:
some_column result
----------- ------
12 ==> 00012
123 ==> 00123
6454 ==> 06454
答案 0 :(得分:24)
如果函数LPAD可用:
SELECT LPAD(some_column, 5, '0')
FROM table
SELECT RIGHT(REPEAT('0', 5) || some_column, 5)
FROM table
some_column | Concatenate five '0's to some_column | Return the five rightmost characters
------------------------------------------------------------------------
12 => 0000012 => 00012
123 => 00000123 => 00123
6454 => 000006454 => 06454