Solved

XML Query - Oracle

Posted on 2014-09-15
2
217 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-
  • 2
2 Comments
 
LVL 73

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 73

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

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
query returning everything 11 91
sql for Oracle views 8 49
FRM-40735:KEY-COMMIT trigger raised unhandled exception ORA-01422 7 56
Extract the first word (before the , ) 2 40
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…
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, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

864 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

20 Experts available now in Live!

Get 1:1 Help Now