10
在DB2中存儲爲VARCHAR的數字之前是否有填充0的方法?在db2中使用0填充varchar數字
像這樣:
some_column result
----------- ------
12 ==> 00012
123 ==> 0
6454 ==> 06454
在DB2中存儲爲VARCHAR的數字之前是否有填充0的方法?在db2中使用0填充varchar數字
像這樣:
some_column result
----------- ------
12 ==> 00012
123 ==> 0
6454 ==> 06454
如果函數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 => 0000=> 0
6454 => 000006454 => 06454