Oracle XML 许多节点

问题描述 投票:0回答:1
I have the following XML in table TEST_XML with one COLUMN "XMLTEXT" that is of type CLOB.
   I want to receive the following table-like results at the end:
   User_Identity                       Product_offer_ID   Keyword
   [email protected]   11990              34861
   [email protected]   11990              35357
   [email protected]   11990              34841


   XML Content:

   <MakeOfferEDRs>
    <EDRs>
     <MakeOffer status="6" bonusRuleID="119621" rewardActionID="191032" rewardTime="2023-09-   07T14:19:56" brandID="1" accountID="11712960353450032">
      <Parameter name="[LOOPBACK_RECOMMENDED_OFFER]">1</Parameter>
      <Products>
       <Product keyword="34861" id="22146"/>
       <Product keyword="35357" id="23146"/>
       <Product keyword="34841" id="22140"/>
       </Products>
      <RecommendationParameters>
       <ProductsNumber max="5"/>
       <Strategies>
        <Strategy name="5 RetSS 1 chain version_all MF Bands" id="16384"/>
       </Strategies>
      </RecommendationParameters>
      <ProductOfferingID>11990</ProductOfferingID>
      <UserIdentities>
       <UserIdentity triggered="1" type="EMAIL">[email protected]</UserIdentity>
      </UserIdentities>
      <UseCaseRunId>20662</UseCaseRunId>
      <UseCaseTypeId>5</UseCaseTypeId>
      <ScheduledCampaignID>62179</ScheduledCampaignID>
    </MakeOffer>
   </EDRs>

   I tried a couple of queries, based on this one, where you'll see that I can either get the    original values in one row (column "Keyword" result "<Product id="22146" keyword="34861"/><Product    id="23146" keyword="35357"/><Product id="22140" keyword="34841"/>") or merged all three result in   one value (column "Keyword2" result "348613535734841"):

从 VGRAMATOV.TEST_XML t, xmltable ( 'MakeOfferEDR/EDR' 传递 xmltype(t.xmltext) 栏目
User_Identity XMLTYPE 路径 './MakeOffer/UserIdentities/UserIdentity', Product_Offering_ID XMLTYPE 路径 './MakeOffer/ProductOfferingID', 关键字 XMLTYPE 路径 './MakeOffer/Products/Product', Keyword2 XMLTYPE 路径 './MakeOffer/Products/Product/@keyword' ) 作为 x

oracle xml-parsing
1个回答
0
投票

下降到

Products/Product
以获取每个关键字,然后返回层次结构以获取其他值:

SELECT x.*
FROM   TEST_XML t
       CROSS APPLY XMLTABLE(
         '/MakeOfferEDRs/EDRs/MakeOffer/Products/Product'
         PASSING XMLTYPE(t.xmltext)
         COLUMNS
           User_Identity       VARCHAR2(200) path './../../UserIdentities/UserIdentity',
           Product_Offering_ID NUMBER path './../../ProductOfferingID',
           Keyword             NUMBER path '@keyword'
       ) x

对于样本数据:

CREATE TABLE test_xml (xmltext) AS
SELECT '<MakeOfferEDRs>
    <EDRs>
     <MakeOffer status="6" bonusRuleID="119621" rewardActionID="191032" rewardTime="2023-09-   07T14:19:56" brandID="1" accountID="11712960353450032">
      <Parameter name="[LOOPBACK_RECOMMENDED_OFFER]">1</Parameter>
      <Products>
       <Product keyword="34861" id="22146"/>
       <Product keyword="35357" id="23146"/>
       <Product keyword="34841" id="22140"/>
       </Products>
      <RecommendationParameters>
       <ProductsNumber max="5"/>
       <Strategies>
        <Strategy name="5 RetSS 1 chain version_all MF Bands" id="16384"/>
       </Strategies>
      </RecommendationParameters>
      <ProductOfferingID>11990</ProductOfferingID>
      <UserIdentities>
       <UserIdentity triggered="1" type="EMAIL">[email protected]</UserIdentity>
      </UserIdentities>
      <UseCaseRunId>20662</UseCaseRunId>
      <UseCaseTypeId>5</UseCaseTypeId>
      <ScheduledCampaignID>62179</ScheduledCampaignID>
    </MakeOffer>
   </EDRs>
</MakeOfferEDRs>' FROM DUAL;

输出:

用户身份 产品_OFFERING_ID 关键字
[email protected] 11990 34861
[email protected] 11990 35357
[email protected] 11990 34841

小提琴

© www.soinside.com 2019 - 2024. All rights reserved.