I have a table like (Here 9 columns with ';'. This is sample table):
create table mytable as (
select
1 ID,
'T1;T2;T3' column_1,
'B1;B5;B10;B13' column_2
from dual
union all
select
2 ID,
'T7;T8;T9;T10,T11',
'B2;B3;B5'
from dual
)
I need target table like:
ID column_1 column_2
1 T1 B1
1 T1 B5
1 T1 B10
1 T1 B13
1 T2 B1
1 T2 B5
1 T2 B10
1 T2 B13
1 T3 B1
1 T3 B5
1 T3 B10
1 T3 B13
2 T7 B2
2 T7 B3
2 T7 B5
2 T8 B2
2 T8 B3
2 T8 B5
2 T9 B2
2 T9 B3
2 T9 B5
2 T10 B2
2 T10 B3
2 T10 B5
2 T11 B2
2 T11 B3
2 T11 B5
I found the below link: pipelined function with cursor parameter oracle but I cannot create function regularly. I create function for only one column but can't loop, and I can't call a table. Here is my function:
create or replace function fun_pipelined(i_str in varchar2)
RETURN sys.odcivarchar2list PIPELINED
IS
v_arr dbms_sql.varchar2_table;
v_i long;
v_cnt number;
i number;
begin
v_arr := pl.split(nvl(i_str,' ,'),',');
v_cnt := regexp_count(nvl(i_str,','), ',') + 1;
i := 1;
loop
exit when i > v_cnt;
v_i := trim(v_arr(i));
pipe row (v_i);
i := i+1;
end loop;
end;
Could you please give me some advice? Thank you