I am trying to take a notes field that is just a big block of text, sample data is below as if I were inserting it into a table.
create table test_table
(
job_number number,
notes varchar2(4000)
)
insert into test_table (job_number,notes)
values (12345,1022089483 notes notes notes notes 1022094450 notes notes notes notes 1022095218 notes notes notes notes)
I need to parse it out so there is a separate record for each notes entry (the 10 digit numbers leading the notes are unix timestamps). so if i were to export to pipe delimited it would look like this:
job_number|notes
12345|1022089483 notes notes notes notes
12345|1022094450 notes notes notes notes
12345|1022095218 notes notes notes notes
I really hope this makes sense. I appreciate any insight.
a few ways of doing this:
note: i’m using
[0-9]{10}as my regex to determine the note (ie any 10 digit number is considered the start of the note).first up, we can take the approach of calculating the max number of notes in any given row, and then do a cartesian join with that number of rows. then filter out each note:
that is ok as long as the number of notes is generally the same (the bigger the differences
the worse this scales, as we are doing a lot of recursive lookups).
in 11g we could use a resursive factored sub query to do the same thing as above, but doesn’t do extra looping:
or from 10g onwards we could use the model clause to make up rows: