Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XML Query - Oracle

Posted on 2014-09-15
2
Medium Priority
?
228 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

730 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