I have a requirement to pad any single digit numbers in a string field with a leading zero. I only need to pad single numeric characters with a leading zero, not string alphabetic characters (A-Z). Below is an example of the current data, along with the expected output for these examples.
Current output Expected output:
9 09
19 19
15 15
F F
UR UR
B B
0 00
4 04
N N
00 00
>Solution :
Use a CASE expression to check whether the column contains only 0 to 9. If true then prefix with 0 else as it is.
Query
select
case when col like '[0-9]'
then '0' + col
else col end as newcol
from tablename;