I'm trying to create a sub-table to reference within a query; the data I need is a separate title and code within a CLOB field like this. Code and title are separated by the semicolon, and each pair is separated by a carriage return (represented by ~).
category | values |
---|---|
offender | S;Student~T;Teacher~O;Other |
reporter | S;Student~T;Teacher~O;Other |
I'd like to pull a table like this:
category | code | title |
---|---|---|
offender | S | Student |
offender | T | Teacher |
offender | O | Other |
reporter | S | Student |
reporter | T | Teacher |
reporter | O | Other |
I'm trying to wrap my head around how to use regexp_substr and can't seem to get it to work, it tells me the command isn't ended properly. The table name is "gen":
select
regexp_substr(replace(replace(replace(gen.values,CHR(10),'~'),CHR(13),'~'),';Please Select;*~~',''),'[^~]+',1,LEVEL) as code_title
from dual
CONNECT BY regexp_substr(code_title,'[^~]+',1,LEVEL) IS NOT NULL
where category = 'Offender';
Any advice (or other best practices for streamlining my query) is very much appreciated!