I have following strings:
with strlist as (
select '#RH1#RH1-GEN#RH1-GEN-RW1' col from dual
union all
select '#RH1#RH1-GEN#RH1-GEN-RW1#RH1-GEN-RW1-RRWA' col from dual
union all
select '#RH1' col from dual
)
select * from strlist
Desired out put is
COL1 COL2 COL3 COL4
RH1 RH1-GEN RH1-GEN-RW1 NULL
RH1 RH1-GEN RH1-GEN-RW1 RH1-GEN-RW1-RRWA
RH1 NULL NULL NULL
Is there an easy way for this?
I tried below.. with few exceptions its working. But am looking for a better/accurate alternative:
with strlist as (
select '#RH1#RH1-GEN#RH1-GEN-RW1' FULLPATH from dual
union all
select '#RH1#RH1-GEN#RH1-GEN-RW1#RH1-GEN-RW1-RRWA' FULLPATH from dual
union all
select '#RH1' FULLPATH from dual
)
select FULLPATH,
SUBSTR (FULLPATH, 1, REGEXP_INSTR(FULLPATH, '(#)+', 1, 2)) PHASE,
SUBSTR (FULLPATH, REGEXP_INSTR(FULLPATH, '(#)+', 1, 2), REGEXP_INSTR(FULLPATH, '(#)+', 1, 3) - REGEXP_INSTR(FULLPATH, '(#)+', 1, 2)) AREA,
SUBSTR (FULLPATH, REGEXP_INSTR(FULLPATH, '(#)+', 1, 3), REGEXP_INSTR(FULLPATH, '(#)+', 1, 4) - REGEXP_INSTR(FULLPATH, '(#)+', 1, 3)) AREA,
SUBSTR (FULLPATH, REGEXP_INSTR(FULLPATH, '(#)+', 1, 4), REGEXP_INSTR(FULLPATH, '(#)+', 1, 5) - REGEXP_INSTR(FULLPATH, '(#)+', 1, 4)) SYSTEM,
SUBSTR (FULLPATH, -REGEXP_INSTR(FULLPATH, '(#)+', 1, 5)) TAG
from strlist