I have been stuck all morning on this and was hoping to get some help. I have been reading what I can find but I am having troubles applying it in my situation.
I have records similar to this:
A123-700
A123-700 / WORD-8
A123 / A456
WORD-8 / A456-800
I need to break these up into a "type" and "series" and ignore "WORD-8"
For example
A123-300 would be type=A123, series=300
A123-300 / WORD-8 would be type=A123, series=300
A123 / A456 would be type=A123, type=A456
WORD-8 / A456-200 would be type=A456, series=200
So far I have something like this:
WITH gen AS
( select 'A123-700' x from dual
UNION ALL
select 'A123-700 / WORD-8' x from dual
union all
select 'A123 / A456' x from dual
union all
select 'WORD-8 / A456-800' x from dual
)
SELECT x ,
regexp_substr(x, '[^/]+') as first_slash,
regexp_substr(x, '[^-]+') as first_type,
regexp_substr(x, '-\w*') as first_series,
regexp_substr(x, '[^/][^DASH]+', 1, 2) as second_slash,
regexp_substr(x, '[^/]+', 1, 2) as second_type,
regexp_substr(x, '-\w+', 1, 2) as second_series
FROM gen;
But the results are not what I was hoping for. I'd like to not have the -, and my "second" info is not coming out right either.
X FIRST_SLASH FIRST_TYPE FIRST_SERIES SECOND_SLASH SECOND_TYPE SECOND_SERIES
A123-700 A123-700 A123 -700 (null) (null) (null)
A123-700 / WORD-8 A123-700 A123 -700 D-8 WORD-8 -8
A123 / A456 A123 A123 / A456 (null) A456 A456 (null)
WORD-8 / A456-800 WORD-8 WORD -8 D-8 / A456-800 -800
Could someone help point me in the right direction?
Thanks!