Stačí použít REPLACE
a váš standardní kód s ,
with temp as
(
select 108 Name, 'test' Project, 'Err1:::Err2:::Err3' Error from dual
union all
select 109, 'test2', 'Err1' from dual
)
select distinct
t.name, t.project,
trim(regexp_substr(REPLACE(t.error, ':::', ', '), '[^,]+', 1, levels.column_value)) as error
from
temp t,
table(cast(multiset(select level from dual connect by level <= length (regexp_replace(REPLACE(t.error, ':::', ', '), '[^,]+')) + 1) as sys.OdciNumberList)) levels
order by name
Nebo je třeba vydělit délkou delimetru:
with temp as
(
select 108 Name, 'test' Project, 'Err1:::Err2:::Err3' Error from dual
union all
select 109, 'test2', 'Err1:::Err2' from dual
)
select distinct
t.name, t.project,
trim(regexp_substr(t.error, '[^:::]+', 1, levels.column_value)) as error
from
temp t,
table(cast(multiset(select level from dual connect by level <= length (
regexp_replace(t.error, '[^:::]+'))/3 + 1) as sys.OdciNumberList)) levels
order by name
Můžete vidět, proč se provádí:
SELECT length (regexp_replace('Err1:::Err2:::Err3', '[^:::]+')) + 1 AS l
FROM dual
To vrátí 7 a vaše:
SELECT DISTINCT t.name, t.project,
trim(regexp_substr(t.error, '[^:::]+', 1, levels.column_value)) as error
se pokusí získat regexp_substr
pro 7 výskytů, kde 4 z nich budou NULL
a nakonec 4 NULL
bude zmáčknuto na jeden NULL
podle DISTINCT
.