Is there built-in function in Oracle DB 11g r2 that could parse varchar2 variable to table? Opposite of listagg or wm_concat. I found only Tom Kyte's method dated 2006:
with data as
(
select trim(substr (txt, instr(txt, ',', 1, level) + 1
, instr(txt, ',', 1, level + 1) - instr(txt, ',', 1, level) - 1)) as token
from (select ',' || :txt || ',' txt from dual)
connect by level <= length(:txt) - length(replace(:txt, ',', '')) + 1
)
select * from data;
I think Oracle must have simpler way.
No.
I would simplify Tom's method slightly, but not by much; you can now use regular expressions as well:
SQL Fiddle
Ben's
regexp_substr
solution is generally the preferred solution. If your string happens to consist of strings that are valid Oracle identifiers-- they are less than or equal to 30 characters and begin with an alphabetic character, you can also use thedbms_utility.comma_to_table
function. Given those limitations, however, it's generally better to use the general-purpose solution.