Oracle XML:提取给定节点中的多个记录

问题描述 投票:0回答:1

有人可以帮忙我如何提取所有的RefID?我将使用什么正确的数据类型?这是下面的XML:

<?xml version="1.0" encoding="UTF-8"?>
<Query xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="OutputQuery">
 <OutputOption>
  <RefId>
     <long>9474841</long>
     <long>9436906</long>
     <long>9506794</long>
  </RefId>
 </OutputOption>
</Query>

Output:

RefID
-----
9474841
9436906
9506794
xml oracle extract
1个回答
0
投票

此查询应该为您提供所需的内容:

select RefId
from
  xmltable(
    '/Query/OutputOption/RefId/long'
    passing xmltype(
      q'[<?xml version="1.0" encoding="UTF-8"?>
<Query xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="OutputQuery">
  <OutputOption>
    <RefId>
       <long>9474841</long>
       <long>9436906</long>
       <long>9506794</long>
    </RefId>
  </OutputOption>
</Query>
      ]'
    )
    columns RefId number path '/'
  )
;

您需要的数据类型是XMLTYPE。

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