Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Difficulty extracting from XMLTYPE column using XMLTABLE

Simon GaddNov 13 2009 — edited Apr 22 2010
Hi Folks.

I am currently trying to shred the contents of an XML document that is stored on our schema in a XMLType column. The XMLYTYPE column is pointing to several schemas that are registered within the database.

If I take a subset of the XML from one of the files and create an XMLTYPE column on the fly, I am able to extract data using the XMLTABLE syntax. If I try the same thing on the XMLTYPE column in the table registered to schemas stored in the database I get no joy.

Please see below for an example.

Please note that this is only a small segment of the original XML document which is very large. The XML document has one <RTDRFileHeader> and <ConnectionList> nodes per document but many <Connection> nodes beneath the <ConnectionList>.

My requirement is to RETRIEVE ALL the data contained in the <Connection> elements beneath the <ConnectionList>. How do I achieve this?
CREATE TABLE ag_test2 as 
SELECT  XMLTYPE(
'<RTDR xmlns:tadig-gen="https://infocentre.gsm.org/TADIG-GEN" xmlns="https://infocentre.gsm.org/TADIG-RTDR">
  <RTDRFileHeader>
    <Prefix>MRTDR</Prefix>
    <Sender>EDSCH</Sender>
    <Recipient>NXTMP</Recipient>
    <PMN>UKRAS</PMN>
    <ReportSeqNo>5</ReportSeqNo>
    <TADIGGenSchemaVersion>2.2</TADIGGenSchemaVersion>
    <RTDRSchemaVersion>1.1</RTDRSchemaVersion>
    <CreationTmstp>2009-09-04T04:04:00.000000+02:00</CreationTmstp>
  </RTDRFileHeader>
<ConnectionList xmlns="https://infocentre.gsm.org/TADIG-RTDR">
 <Connection xmlns="https://infocentre.gsm.org/TADIG-RTDR">
      <VPMN>UKRAS</VPMN>
      <HPMN>LIEK9</HPMN>
      <FileItemList>
        <FileItem>
          <FileID>CDUKRASLIEK901274-00005-m</FileID>
          <ExchTmstp>2009-08-24T12:07:22.000000+02:00</ExchTmstp>
          <FileType>
            <InitTAP>
              <TAPSeqNo>1274</TAPSeqNo>
              <NotifFileInd>true</NotifFileInd>
              <ChargeInfo>
                <TAPTxCutoffTmstp>2009-08-24T12:52:10.000000+03:00</TAPTxCutoffTmstp>
                <TAPAvailTmstp>2009-08-24T11:52:10.000000+02:00</TAPAvailTmstp>
                <TAPCurrency>SDR</TAPCurrency>
                <TotalNetCharge>0</TotalNetCharge>
                <TotalTax>0</TotalTax>
              </ChargeInfo>
            </InitTAP>
          </FileType>
        </FileItem>
        <FileItem>
          <FileID>CDUKRASLIEK901280-00005-m</FileID>
          <ExchTmstp>2009-08-30T12:14:39.000000+02:00</ExchTmstp>
          <FileType>
            <InitTAP>
              <TAPSeqNo>1280</TAPSeqNo>
              <NotifFileInd>true</NotifFileInd>
              <ChargeInfo>
                <TAPTxCutoffTmstp>2009-08-30T12:52:34.000000+03:00</TAPTxCutoffTmstp>
                <TAPAvailTmstp>2009-08-30T11:52:34.000000+02:00</TAPAvailTmstp>
                <TAPCurrency>SDR</TAPCurrency>
                <TotalNetCharge>0</TotalNetCharge>
                <TotalTax>0</TotalTax>
              </ChargeInfo>
            </InitTAP>
          </FileType>
        </FileItem>
      </FileItemList>
    </Connection>
 </ConnectionList>
 </RTDR> ') as xml from dual
 
Question: When I run the following query no rows are returned although the table is populated with XML segment above. Any explanation as to why and how can I resolve this?
SELECT rtd2."VPMN"
      ,rtd2."Recipient"
      ,rtd2."ReportSeqNo"
FROM   ag_test2  r
      ,XMLTABLE('/RTDR'
                PASSING  r.xml
                COLUMNS  "VPMN"       VARCHAR2(5)    PATH '/RTDRFileHeader/ConnectionList/Connection/VPMN'  
                        ,"Recipient"    VARCHAR2(5)  PATH '/RTDRFileHeader/Recipient'
                        ,"ReportSeqNo"  INTEGER      PATH '/RTDRFileHeader/ReportSeqNo'
                ) rtd2; 
From my other investigations the following query works OK when the same XML segment is created dynamically by performing an SELECT XMLTYPE ... FROM DUAL compared to the method above. Can anybody provide an explanation?
WITH t as (select XMLTYPE(
'<RTDR>
  <RTDRFileHeader>
    <Prefix>MRTDR</Prefix>
    <Sender>EDSCH</Sender>
    <Recipient>NXTMP</Recipient>
    <PMN>UKRAS</PMN>
    <ReportSeqNo>5</ReportSeqNo>
    <TADIGGenSchemaVersion>2.2</TADIGGenSchemaVersion>
    <RTDRSchemaVersion>1.1</RTDRSchemaVersion>
    <CreationTmstp>2009-09-04T04:04:00.000000+02:00</CreationTmstp>
  </RTDRFileHeader>
<ConnectionList>
 <Connection>
      <VPMN>UKRAS</VPMN>
      <HPMN>LIEK9</HPMN>
      <FileItemList>
        <FileItem>
          <FileID>CDUKRASLIEK901274-00005-m</FileID>
          <ExchTmstp>2009-08-24T12:07:22.000000+02:00</ExchTmstp>
          <FileType>
            <InitTAP>
              <TAPSeqNo>1274</TAPSeqNo>
              <NotifFileInd>true</NotifFileInd>
              <ChargeInfo>
                <TAPTxCutoffTmstp>2009-08-24T12:52:10.000000+03:00</TAPTxCutoffTmstp>
                <TAPAvailTmstp>2009-08-24T11:52:10.000000+02:00</TAPAvailTmstp>
                <TAPCurrency>SDR</TAPCurrency>
                <TotalNetCharge>0</TotalNetCharge>
                <TotalTax>0</TotalTax>
              </ChargeInfo>
            </InitTAP>
          </FileType>
        </FileItem>
        <FileItem>
          <FileID>CDUKRASLIEK901280-00005-m</FileID>
          <ExchTmstp>2009-08-30T12:14:39.000000+02:00</ExchTmstp>
          <FileType>
            <InitTAP>
              <TAPSeqNo>1280</TAPSeqNo>
              <NotifFileInd>true</NotifFileInd>
              <ChargeInfo>
                <TAPTxCutoffTmstp>2009-08-30T12:52:34.000000+03:00</TAPTxCutoffTmstp>
                <TAPAvailTmstp>2009-08-30T11:52:34.000000+02:00</TAPAvailTmstp>
                <TAPCurrency>SDR</TAPCurrency>
                <TotalNetCharge>0</TotalNetCharge>
                <TotalTax>0</TotalTax>
              </ChargeInfo>
            </InitTAP>
          </FileType>
        </FileItem>
      </FileItemList>
    </Connection>
 </ConnectionList>
 </RTDR> ') as xml from dual )
--
SELECT rtd2."VPMN"
      ,rtd2."HPMN"
FROM   t  r
      ,XMLTABLE('/RTDR/ConnectionList'
                PASSING  r.xml
                COLUMNS  "VPMN"       VARCHAR2(5)    PATH '/ConnectionList/Connection/VPMN'  
                        ,"HPMN"       VARCHAR2(5)    PATH '/ConnectionList/Connection/HPMN'  
                ) rtd2;
 
Any comments, suggestions, pointers gratefully received.

Many thanks

Kind regards

Simon Gadd
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 20 2010
Added on Nov 13 2009
19 comments
5,505 views