繁体   English   中英

从列中提取值(xmltype)

[英]Extract value from column (xmltype)

我们正在使用 ERP 系统。 我是 XML 新手。

在我们的系统中,我们有一列XML_DATA ,其 TYPE 为xmltype(2000)

架构:

<?xml version="1.0" ?> 
- <xs:schema xmlns:xs=" " attributeFormDefault="qualified"  elementFormDefault="qualified">
 - <xs:element name="XK6">
  - <xs:complexType>
   - <xs:choice maxOccurs="unbounded">

   - <xs:element name="Product">
    - <xs:complexType>
     - <xs:sequence>
      - <xs:element name="Product_row" minOccurs="0" maxOccurs="unbounded">
       - <xs:complexType>
        - <xs:sequence>

        <xs:element name="DETAIL" type="Product_DETAIL" minOccurs="0" /> 

          </xs:sequence>
         </xs:complexType>
        </xs:element>
       </xs:sequence>
      </xs:complexType>
     </xs:element>
    </xs:choice>
   </xs:complexType>
  </xs:element>

  - <xs:simpleType name="Product_DETAIL">
   - <xs:restriction base="xs:string">
    <xs:maxLength value="1000" /> 
   </xs:restriction>
  </xs:simpleType>
 </xs:schema>

编辑:

XML:

<?xml version="1.0" encoding="utf-8" ?> 
- <XP6>
  +<collapsed_node>
  +<collapsed_node>
  +<collapsed_node>
  - <Product>
    - <Product_row>
       <DETAIL>sometext </DETAIL> 
      </Product_row>
    </Product>
  </XP6>

我怎样才能提取列?

或者需要更多的数据来做到这一点? 我想获得Product_Detail值。

使用“XMLTABLE”函数(参见https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions228.htm ):

with d as (
select xmltype('
<XK6>
    <Product>
        <Product_row>
            <DETAIL>First product detail</DETAIL>
        </Product_row>
        <Product_row>
            <DETAIL>Second product detail</DETAIL>
        </Product_row>
    </Product>
</XK6>'
) as thexml from dual)
select detail from d, 
  xmltable('/XK6/Product/Product_row' 
    passing d.thexml 
    columns detail varchar2(100) path 'DETAIL') 

暂无
暂无

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

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