How to use base SQL to parse a very, very long string into many columns by a delimiter?
I’ve been through a few posts (here for example, and here or here) on parsing into separate columns, rows, et cetera. They all however seem to manually identify and create each column. (Here, for example, the example includes three columns, the maximum number needed). I need up to 90 columns. I’m looking for a way to consolidate, or functionalize, the parsing into multiple columns so I don’t need to repeat the equivalent of ‘,nullif(split_part(my_string,’|’,N),”) string_N’ from below 90 times.
select
id
,nullif(split_part(my_string,'|',1),'') string_1
,nullif(split_part(my_string,'|',2),'') string_2
,nullif(split_part(my_string,'|',3),'') string_3
,nullif(split_part(my_string,'|',4),'') string_4
from
(with test_data (id, my_string) as
(
select 1, 'a|b|c|d' from dual union all
select 2, 'abba|zabba|beta' from dual union all
select 5, 'x|y' from dual union all
select 4, 'z1|z2|z3' from dual
)
select id, my_string
from test_data
)
;
I’ve tried building the solution manually, as above. Doing it for very, very long strings would create problems for me. The posted SQL solutions aren’t getting there and I can’t use python.