繁体   English   中英

XMLTable无法从XML的子级获取数据

[英]XMLTable doesn't get data from children in XML

我需要使用XMLTable来获取XML数据块,以获取bulletinWorkl:idbulletinWork/outOfServices/outOfService/document:destinationName

<?xml version="1.0" encoding="ISO-8859-1"?>
<cern:bulletinWork id="5307cedc-2208-3701-9b9d-e69664b1ef31">
  <cern:outOfServices>
    <cern:outOfService id="e95d491b-2876-3e08-901f-b0f79be86bfb">
      <cern:document destinationName="MonsA" type="S427"></cern:document>
    </cern:outOfService>
    <cern:outOfService id="fab04992-a33f-3a8c-ad16-29cd54fb93d6">
      <cern:document destinationName="MonsB" type="S427"></cern:document>
    </cern:outOfService>
  </cern:outOfServices>
</cern:bulletinWork>

我正在尝试运行此查询,但是我成功取回bulletinWork的ID属性,但是bulletinWork/outOfServices/outOfService/document的destinationName为空。

select X.Id, X.DestinationName from S1589_XML_Bulletin, XMLTABLE(
    '$d/*:bulletinWork'
    PASSING XMLTYPE(XML_RAW) as "d"
    COLUMNS
        Id                  VARCHAR2(50) PATH   '@*:id',
        DestinationName     VARCHAR2(50) PATH   '*:outOfServices/*:outOfService/*:document/*:destinationName'
) AS X

有人看到我在做什么错吗? 我需要得到:

Id                                       DestinationName
-------------------------------------    ------------------
5307cedc-2208-3701-9b9d-e69664b1ef31     MonsA
5307cedc-2208-3701-9b9d-e69664b1ef31     MonsB
 COLUMNS
        Id                  VARCHAR2(50) PATH   '@id',
        DestinationName     VARCHAR2(50) PATH   'string-join(distinct-values(*:outOfServices/*:outOfService/*:document/@destinationName),", ")'

您不必为未添加前缀的属性使用名称空间。 它们的名称空间定义为父元素。

在示例xml中,有多个cern:outOfService这就是为什么我使用string-joindistinct-values cern:outOfService值的原因

更新:

1)对我来说更长,但更清晰。 两个xml表的联接。

    select * from xmltable('*:bulletinWork' passing xmltype('<cern:bulletinWork id="5307cedc-2208-3701-9b9d-e69664b1ef31" xmlns:cern="aaa">
      <cern:outOfServices>
        <cern:outOfService id="e95d491b-2876-3e08-901f-b0f79be86bfb">
          <cern:document destinationName="MonsA" type="S427"></cern:document>
        </cern:outOfService>
        <cern:outOfService id="fab04992-a33f-3a8c-ad16-29cd54fb93d6">
          <cern:document destinationName="MonsB" type="S427"></cern:document>
        </cern:outOfService>
      </cern:outOfServices>
    </cern:bulletinWork>')
    COLUMNS
            Id                  VARCHAR2(50) PATH   '@id',
            outOfServices       xmltype   path '*:outOfServices'  
    ) t1 
    ,xmltable('*:outOfServices/*:outOfService' passing t1.outOfServices 
    COLUMNS DestinationName     VARCHAR2(50) PATH   '*:document/@destinationName')

2)从子节点访问父节点。

select * from xmltable('*:bulletinWork/*:outOfServices/*:outOfService' passing xmltype('<cern:bulletinWork id="5307cedc-2208-3701-9b9d-e69664b1ef31" xmlns:cern="aaa">
  <cern:outOfServices>
    <cern:outOfService id="e95d491b-2876-3e08-901f-b0f79be86bfb">
      <cern:document destinationName="MonsA" type="S427"></cern:document>
    </cern:outOfService>
    <cern:outOfService id="fab04992-a33f-3a8c-ad16-29cd54fb93d6">
      <cern:document destinationName="MonsB" type="S427"></cern:document>
    </cern:outOfService>
  </cern:outOfServices>
</cern:bulletinWork>')
COLUMNS
        Id                  VARCHAR2(50) PATH   './../../@id', 
        DestinationName     VARCHAR2(50) PATH   '*:document/@destinationName'
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM