This is not a correct JSON, so you're unable to use Oracle's builtin functions for processing json
data. Maybe you could alter text to be a correct JSON but in my opinion there is a more simple solution.
If this text has a fixed structure where every value is in a new line and preceded by key:
, then you could use:
- regular expressions:
regexp_substr
(for extracting each key:value
line) then regexp_replace
to get value
only
connect by
to get recursively all values.
Look at the example below:
with mytable as (
select 'json data{'||chr(10)||
' first:one'||chr(10)||
' second:two'||chr(10)||
' third:three'||chr(10)||
' }' as json_data_col
from dual
)
select (regexp_replace(regexp_substr(json_data_col, '^(.+:){1}(.*)$', 1, level, 'm'), '(^.*:)(.*)($)', '\2', 1, 1)) as extracted_value
from mytable
connect by regexp_substr(json_data_col, '^(.+:){1}(.*)$', 1, level, 'm') is not NULL
;