with src as
(
select 'A001' col1, 'A1;A2;A3' col2 from dual union all
select 'B002', 'B1' from dual union all
select 'C003', 'C1;C2' from dual union all
select 'D004', 'D1;D2;D3;D4' from dual union all
select 'E005', 'E1' from dual
)
, explode as
(
select col1
, regexp_substr(col2, '\w+', 1, 1) as col2_1
, regexp_substr(col2, '\w+', 1, 2) as col2_2
, regexp_substr(col2, '\w+', 1, 3) as col2_3
, regexp_substr(col2, '\w+', 1, 4) as col2_4
-- if there is more add more...
from src
)
select col1, col2_1 from explode where col2_1 is not null union all
select col1, col2_2 from explode where col2_2 is not null union all
select col1, col2_3 from explode where col2_3 is not null union all
select col1, col2_4 from explode where col2_4 is not null
order by col1
;
结果:
/*
A001 A1
A001 A2
A001 A3
B002 B1
C003 C2
C003 C1
D004 D1
D004 D4
D004 D2
D004 D3
E005 E1
*/