从列中提取值 (xmltype)

Extract value from column (xmltype)

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

的新手

在我们的系统中,我们有一个列 XML_DATA,其类型是 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')