Solved

Querying XML data producing incorrect results.

Posted on 2011-09-07
3
295 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
Comment Utility
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
Comment Utility
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
Comment Utility
THanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

763 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

11 Experts available now in Live!

Get 1:1 Help Now