How can I split a string by comma using oracle sql? Here I have a column which has values like below
123Lcq
Lf32i
jkp32m
I want to split it by comma
1,2,3,L,c,q
L,f,3,2,i
j,k,p,3,2,m
How can I split a string by comma using oracle sql? Here I have a column which has values like below
123Lcq
Lf32i
jkp32m
I want to split it by comma
1,2,3,L,c,q
L,f,3,2,i
j,k,p,3,2,m
You could use regexp_replace:
SELECT substr(regexp_replace(mycol, '(.)', ',\1'), 2)
FROM mytable
The regular expression finds every character, and those matching characters are then all prefixed with commas. Finally a simple substr is used to eliminate the first comma.
Note that trimming commas could be an alternative to substr, but the behaviour is different when the original value already has commas at the end of the string: when trimming, you also trim away these original commas.