Here is the DDL --
create table tbl1 (
id number,
value varchar2(50)
);
insert into tbl1 values (1, \'AA, UT, BT, SK, SX\');
insert into tbl1 values (
Vercelli posted a correct answer. However, with more than one string to split, connect by
will generate an exponentially-growing number of rows, with many, many duplicates. (Just try the query without distinct
.) This will destroy performance on data of non-trivial size.
One common way to overcome this problem is to use a prior
condition and an additional check to avoid cycles in the hierarchy. Like so:
select id, trim(regexp_substr(value,'[^,]+', 1, level) ) value, level
from tbl1
connect by regexp_substr(value, '[^,]+', 1, level) is not null
and prior id = id
and prior sys_guid() is not null
order by id, level;
See, for example, this discussion on OTN: https://community.oracle.com/thread/2526535