簡體   English   中英

Oracle SQL XML 摘錄

[英]Oracle SQL XML extract

我正在嘗試使用 oracle SQL 從 XML 中提取數據,但返回 XML 值。 這是我的 XML:

<?xml version="1.0"?>
<fileinfo>
<header>
<system>ABC</system>
<fileID>1</fileID>
</header>
<data>
<Linearcurve>
<fieldID>123</fieldID>
<fieldName>EFG</fieldName>
<Curve>
<curveID>1</curveID>
<xvalue>23</xvalue>
<lastUpdated>
<month>01</month>
<day>01</day>
<year>2001</year>
<hour>01</hour>
<minute>01</minute>
<second>01</second>
</lastUpdated>
<value>
<valueID>1</valueID>
<lowerCurve>
<points>
<point1>0.22</point1>
</points>
</lowerCurve>
</value>
<value>
<valueID>2</valueID>
<lowerCurve>
<points>
<point1>-0.22</point1>
</points>
</lowerCurve>
</value>
</Curve>
</Linearcurve>

我正在嘗試提取valueIDpoint1值但返回一個空白值這是我的腳本

WITH XML_CTE as (select xml.* from file1 u, XMLTABLE('//Linearcurve/Curve'
    PASSING XMLTYPE(u.xmlfile)
    COLUMNS
        curveID PATH './../fieldID'
             ,curveID PATH 'curveID'
        ,valueID PATH '//Curve/value/valueID'
        ,point1 PATH '//value/lowerCurve/points/point1' 
    ) xml
)
select * from xml_cte

理想情況下,返回將包括 valueID 1 point1 0.22 valueID 2 poing1 -0.22

你可以這樣做:

select x.*
from file1 f1
cross join xmltable (
  '//Linearcurve/Curve/value'
  passing xmltype(f1.xmlfile)
  columns
    fieldID PATH './../../fieldID'
   ,curveID PATH './../curveID'
   ,valueID PATH 'valueID'
   ,point1 PATH 'lowerCurve/points/point1' 
) x;

FIELDID | CURVEID | VALUEID | POINT1
:------ | :------ | :------ | :-----
123     | 1       | 1       | 0.22  
123     | 1       | 2       | -0.22 

db<>小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM