简体   繁体   English

Oracle SQL XML 摘录

[英]Oracle SQL XML extract

I am trying to extract data from XML using oracle SQL but returns null value.我正在尝试使用 oracle SQL 从 XML 中提取数据,但返回 XML 值。 This is my 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>

I am trying to extract valueID and point1 values but return a blank value Here is my script我正在尝试提取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

Ideally the return would include valueID 1 point1 0.22 valueID 2 poing1 -0.22理想情况下,返回将包括 valueID 1 point1 0.22 valueID 2 poing1 -0.22

You can do this with:你可以这样做:

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<>fiddle db<>小提琴

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

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