Solved

XML Query - Oracle

Posted on 2014-09-15
2
221 Views
Last Modified: 2014-10-02
Hi All, a while back I was helped on here with an XML query. The Query works but I am having trouble querying out a new object (signature URL)


The query returns all the required information, except not on the URL in signatureURL.


This is the Query.
SELECT DISTINCT 
       c.taxid,
       CASE WHEN c.taxid != '0' OR LENGTH(c.id) = 5 THEN c.taxid ELSE REGEXP_SUBSTR(c.id, '^[^- ]+') END chain,
       CASE WHEN LENGTH(c.id) = 5 THEN c.id ELSE REGEXP_SUBSTR(c.id, '[^- ]+$') END customer,
       CASE WHEN c.taxid is null then '0' else c.taxid end as taxid,
       c.mtime,
       o.owner,
       o.signature,
       o.sku,
       o.qty
  FROM xml_data_tab t,
       XMLTABLE(
           '//customer'
           PASSING t.xml_data
           COLUMNS cust_seq FOR ORDINALITY,
                   id VARCHAR2(50) PATH '/customer/id',
                   taxid VARCHAR2(50) PATH '/customer/taxID',
                   mtime VARCHAR2(50) PATH '/customer/billTo/mtime'
       ) c,
       XMLTABLE(
           '//lines'
           PASSING t.xml_data
           COLUMNS line_seq FOR ORDINALITY, node XMLTYPE PATH '.'
       ) l,
       XMLTABLE(
           '//object'
           PASSING l.node
           COLUMNS 
                   signature VARCHAR2(100) PATH '/object/signatureURL',
                   owner VARCHAR2(50) PATH '/object/owner',
                   sku VARCHAR2(50) PATH '/object/sku',
                   qty VARCHAR2(50) PATH '/object/qty'
       ) o
 WHERE  l.line_seq = c.cust_seq

Open in new window


This is the XML
<object type="hash">
<otherVersions type="list"/>
<percentDiscount type="null"/>
<entityType>SalesOrder</entityType>
<ownerName>John test</ownerName>
<mtime>2014-09-15T16:12:06Z</mtime>
<owner>johnt@test.com</owner>
<promoDetails type="null"/>
<shippingMethod>FEDEX</shippingMethod>
<id>#1140021</id>
<category>/api/v3/order_categories/4960</category>
<realVersionID type="null"/>
<paymentTerms>PREPAID</paymentTerms>
<uuid>da6ca3b0-7dcf-46b8-9ee7-c462fead60f4</uuid>
<ctimeOnServer>2014-09-15T16:12:06Z</ctimeOnServer>
<freeShipping type="boolean">False</freeShipping>
<realVersion type="null"/>
<startShipDate type="null"/>
<versionType type="null"/>
<mtimeOnServer>2014-09-15T16:12:31Z</mtimeOnServer>
<shipPartial type="boolean">True</shipPartial>
<userGroup>/api/v3/user_groups/2</userGroup>
<totalAmount>131.88</totalAmount>
<subtotalAmount>131.88</subtotalAmount>
<status>Open</status>
<customer type="hash">...</customer>
<shipTo type="hash">...</shipTo>
<defaultWarehouse>/api/v3/warehouses/158611</defaultWarehouse>
<sourceType>seller</sourceType>
<billTo type="hash">...</billTo>
<creditCard type="null"/>
<lastExported type="null"/>
<cdate>2014-09-15</cdate>
<photoURLs type="list"/>
<versionInfo type="null"/>
<signatureURL>
https://app.test.com/tempFile/b81f73fd-e09d-4786-9459-7976d49d7bb4-signature-1140021-1cfb47a5cd88f397e70b9e46b1d6422b08800f3b.png
</signatureURL>
<shippedStatus>Not Shipped</shippedStatus>
<priceLists type="list"/>
<totalOffDiscount type="null"/>
<ctime>2014-09-15T16:11:39Z</ctime>
<notes/>
<promoCode type="null"/>
<lines type="list">...</lines>
<cancelDate type="null"/>
<objID type="integer">1140021</objID>
<lastEdited>2014-09-15T16:12:31Z</lastEdited>
<customerPO type="null"/>
<realVersionUUID type="null"/>
<resource_uri>/api/v3/orders/1140021</resource_uri>
</object>

Open in new window

0
Comment
Question by:FutureDBA-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 40323643
Your objects aren't children of the l.node, they are at the parent, so you need to pass in the whole document

change
     PASSING l.node
to
     PASSING t.xml_data
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 40323648
alternatively, remove the "o" xmltable, and combine with the customer extractions

   SELECT DISTINCT
          c.taxid,
          CASE
              WHEN c.taxid != '0' OR LENGTH(c.id) = 5 THEN c.taxid
              ELSE REGEXP_SUBSTR(c.id, '^[^- ]+')
          END
              chain,
          CASE WHEN LENGTH(c.id) = 5 THEN c.id ELSE REGEXP_SUBSTR(c.id, '[^- ]+$') END customer,
          CASE WHEN c.taxid IS NULL THEN '0' ELSE c.taxid END AS taxid,
          c.mtime,
          c.owner,
          c.signature,
          c.sku,
          c.qty
     FROM xml_data_tab t,
          XMLTABLE(
              '/object'
              PASSING t.xml_data
              COLUMNS cust_seq FOR ORDINALITY,
                      id VARCHAR2(50) PATH '/object/customer/id',
                      taxid VARCHAR2(50) PATH '/object/customer/taxID',
                      mtime VARCHAR2(50) PATH '/object/customer/billTo/mtime',
                      signature VARCHAR2(100) PATH '/object/signatureURL',
                      owner VARCHAR2(50) PATH '/object/owner',
                      sku VARCHAR2(50) PATH '/object/sku',
                      qty VARCHAR2(50) PATH '/object/qty'
          ) c,
          XMLTABLE(
              '//lines'
              PASSING t.xml_data
              COLUMNS line_seq FOR ORDINALITY, node XMLTYPE PATH '.'
          ) l
         
    WHERE l.line_seq = c.cust_seq
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

726 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