Can I turn multiple values stored in a single field into a set of rows from within a select statement?

StackOverflow https://stackoverflow.com/questions/17885395

  •  04-06-2022
  •  | 
  •  

Frage

This is asked regarding an Oracle 11g database.

I'm trying to query an Atlassian Confluence calendar table. It stores calendar entries for an entire calendar into a single value in a single row, which is this gigantic glob of iCal crap.

If the fields within each entry were in a consistent order, my regex fu would be strong enough to parse out the particular entry I am searching for... but since I need to search for a date, the description, and the summary, all of which can apparently be in any order within the BEGIN/END VEVENT, this is impossible. I'm halfway certain it would be impossible even with lookahead and lookbehind.

Is there a sql (not pl-sql) construction that would chop this single string/blob value out into multiple rows, so that I could do something like:

select * from (chopped up value) where x like '%something%';

This would make it sort of the reverse of a wm_concat() or group_concat...

A typical entry looks something like this (and it has 50 or 60 already):

BEGIN:VEVENT
UID:20130724T153322Z--922125579@atlassianzzz.zzz.edu
SUMMARY:Richard Smichard
ATTENDEE;X-CONFLUENCE-USER=rismich:https://atlassianzzz.zzz.edu/c
 onfluence/display/~rismich
LOCATION:
DESCRIPTION:Primary
DTSTART;VALUE=DATE:20130726
DTEND;VALUE=DATE:20130729
DTSTAMP:20130724T153322Z
CREATED:20130724T153322Z
LAST-MODIFIED:20130724T153322Z
ORGANIZER;X-CONFLUENCE-USER=botard:MAILTO:botard@zzz.edu
SEQUENCE:0
END:VEVENT

I can't use PL-SQL or build a proper parser because the environment this will run in doesn't make that possible. I get to run a select statement, and it either returns the value I'm looking for, or it doesn't.

Also, NoSQL sucks. Big time.

War es hilfreich?

Lösung

This is a quick test:

with w1 as
(
  select 'BEGIN:VEVENT\
UID:20130724T153322Z--922125579@atlassianzzz.zzz.edu
SUMMARY:Richard Smichard
ATTENDEE;X-CONFLUENCE-USER=rismich:https://atlassianzzz.zzz.edu/c
 onfluence/display/~rismich
LOCATION:
DESCRIPTION:Primary
DTSTART;VALUE=DATE:20130726
DTEND;VALUE=DATE:20130729
DTSTAMP:20130724T153322Z
CREATED:20130724T153322Z
LAST-MODIFIED:20130724T153322Z
ORGANIZER;X-CONFLUENCE-USER=botard:MAILTO:botard@zzz.edu
SEQUENCE:0
END:VEVENT' text from dual
),
w2 as
(
  select 'SUMMARY' label from dual
  union all
  select 'DESCRIPTION' label from dual
)
select regexp_substr(w1.text, 'UID.*') id, w2.label,
       substr(regexp_substr(w1.text, w2.label || '.*'),
              instr(regexp_substr(w1.text, w2.label || '.*'), ':') + 1) spl
from w1, w2;

It gives:

1   UID:20130724T153322Z--922125579@atlassianzzz.zzz.edu    SUMMARY Richard Smichard
2   UID:20130724T153322Z--922125579@atlassianzzz.zzz.edu    DESCRIPTION Primary
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top