Brug bare REPLACE
og din standardkode med ,
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
Eller du skal dividere med længden af delimeter:
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
Du kan se, hvorfor du udfører:
SELECT length (regexp_replace('Err1:::Err2:::Err3', '[^:::]+')) + 1 AS l
FROM dual
Dette vil returnere 7 og din:
SELECT DISTINCT t.name, t.project,
trim(regexp_substr(t.error, '[^:::]+', 1, levels.column_value)) as error
vil prøve at hente regexp_substr
for 7 forekomster, hvor 4 af dem vil være NULL
og til sidst 4 NULL
vil blive klemt til én NULL
ved DISTINCT
.