Solved

Querying XML data producing incorrect results.

Posted on 2011-09-07
3
296 Views
Last Modified: 2012-05-12
Hi Everyone.

I am trying to query some xml data that i have in a clob in my oracle database.

the xml file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Race>
  <RaceID>1</RaceID>
  <RaceType>Match</RaceType>
  <Course>
    <CompoundMark CompoundMarkID="1">
      <Mark SeqID="1" Lat="38.697406" Lng="-9.401273">  </Mark>
    </CompoundMark>
    <CompoundMark CompoundMarkID="2">
      <Mark SeqID="1" Lat="38.697301" Lng="-9.402718">   </Mark>
      <Mark SeqID="2" Lat="38.697301" Lng="-9.402718">   </Mark>
    </CompoundMark>
    <CompoundMark CompoundMarkID="3">
      <Mark SeqID="1" Lat="38.694322" Lng="-9.406006">   </Mark>
    </CompoundMark>
    
  </Course>
  
</Race>

Open in new window


The query i am using is


SELECT EXTRACTVALUE(VALUE(r), '/Race/RaceID') Raceid,
       EXTRACTVALUE(VALUE(d), '/CompoundMark/@CompoundMarkID') MarkID,
       EXTRACTVALUE(VALUE(e), '//Mark/@Lat') Lat,
       EXTRACTVALUE(VALUE(e), '//Mark/@Lng') Lng,
       EXTRACTVALUE(VALUE(e), '//Mark/@SeqID') SeqID
  FROM ext_clob_table,
       TABLE(XMLSEQUENCE(EXTRACT(xmltype(text), '/Race'))) r,
       TABLE(XMLSEQUENCE(EXTRACT(r.COLUMN_VALUE, '//CompoundMark'))) d,
       TABLE(XMLSEQUENCE(EXTRACT(r.COLUMN_VALUE, '//Mark')))     e
       

The output i am getting is

RACEID      MARKID      LAT      LNG      SEQID
1      1      38.697406      -9.401273 1
1      1      38.697301      -9.402718       1
1      1      38.697301      -9.402718       2
1      1      38.694322      -9.406006       1
1      2      38.697406      -9.401273       1
1      2      38.697301      -9.402718       1
1      2      38.697301      -9.402718       2
1      2      38.694322      -9.406006       1
1      3      38.697406      -9.401273       1
1      3      38.697301      -9.402718       1
1      3      38.697301      -9.402718       2
1      3      38.694322      -9.406006       1

where as what i want is

RACEID      MARKID      LAT      LNG      SEQID
1      1      38.697406      -9.401273 1
1      2      38.697301      -9.402718       1
1      2      38.697301      -9.402718       2
1      3      38.694322      -9.406006       1


Please help!
0
Comment
Question by:cesarchavez
  • 2
3 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 36500504
SELECT EXTRACTVALUE(VALUE(r), '/Race/RaceID') raceid,
       EXTRACTVALUE(VALUE(d), '/CompoundMark/@CompoundMarkID') markid,
       EXTRACTVALUE(VALUE(e), '/Mark/@Lat') lat,
       EXTRACTVALUE(VALUE(e), '/Mark/@Lng') lng,
       EXTRACTVALUE(VALUE(e), '/Mark/@SeqID') seqid
  FROM ext_clob_table,
       TABLE(XMLSEQUENCE(EXTRACT(xmltype(text), '/Race'))) r,
       TABLE(XMLSEQUENCE(EXTRACT(r.COLUMN_VALUE, '//CompoundMark'))) d,
       TABLE(XMLSEQUENCE(EXTRACT(d.column_value, '//Mark'))) e
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 36500507
the difference is the e reference


old  -  TABLE(XMLSEQUENCE(EXTRACT(r.COLUMN_VALUE, '//Mark')))     e

new -  TABLE(XMLSEQUENCE(EXTRACT(d.column_value, '//Mark'))) e
0
 

Author Closing Comment

by:cesarchavez
ID: 36503949
THanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle SQL 6 48
Oracle 10g - insert string with special characters 8 41
Oracle SQL syntax check  without executing 6 37
SQL Developer 6 33
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now