create table T_VALUES (
VAL varchar2(20)
);
insert into T_VALUES values ('A');
insert into T_VALUES values ('B');
insert into T_VALUES values ('C');
insert into T_VALUES values ('D');
create table T_JOBS (
JOB_ID int,
STR_LIST varchar2(50)
);
insert into T_JOBS values (1, 'r, e, ''Hello'' A w: B, xyz');
insert into T_JOBS values (2, 'ok, D ');
select
job_id,
val
from
T_VALUES
natural join (
select
job_id,
regexp_substr(str_list, '[^ ,]+', 1, occ) as val
from
T_JOBS
cross join (
select level as occ from dual
connect by level <= (select max(length(str_list)) from T_JOBS)
)
)
order by 1, 2
フィドル
編集 :
改良版 (Ben のアイデアを使用)
create table T_VALUES (
VAL varchar2(20)
);
insert into T_VALUES values ('A');
insert into T_VALUES values ('B');
insert into T_VALUES values ('C');
insert into T_VALUES values ('D');
create table T_JOBS (
JOB_ID int,
STR_LIST varchar2(50)
);
insert into T_JOBS values (1, 'junk, values=A:NotA:B:r:e, more_junk');
insert into T_JOBS values (2, 'ok, values=D ');
create type nt_str as table of varchar2(50);
select
j.job_id,
v.val
from
T_JOBS j,
table(
cast(
multiset(
select
regexp_substr(
regexp_substr(j.str_list, 'values=([^, ]+)', 1, 1, 'i', 1),
'[^:]+', 1, level)
from dual
connect by
regexp_substr(
regexp_substr(j.str_list, 'values=([^, ]+)', 1, 1, 'i', 1),
'[^:]+', 1, level) is not null
) as nt_str
)
) t
join T_VALUES v
on v.val = t.column_value
order by 1, 2
もう1つのフィドル