使用XMLtable / Xpath转换XML Clob并将其存储在数据库表

时间:2016-09-27 09:10:00

标签: xml plsql oracle10g extract xmltable

我正在尝试使用Oracle Pl / SQL将XMl提取到行和列中,但是没有以所需格式获取

XML: -

<QualificationCriterion name="iPass Roaming Zone 1" description="" id="##PC4.0##183647208" status="CheckedIn" kind="Implementation" eventName="##PC4.0##67625472">
    <Condition xsi:type="LogicalExpression" expressionType="AND" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Operands>
            <Operand xsi:type="LogicalExpression" expressionType="AND">
                <Operands>
                    <Operand xsi:type="Comparison" expressionType="NE" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6249415" entity="Event" entityName="##PC4.0##67625472" attributeName="Service filter"/>
                        <RightOperand xsi:type="ValueRef" type="##PC4.0##6249415" name="Pseudo Allowance "/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##76915825" entity="Customer" entityName="##PC4.0##701" attributeName="Last BLIMPACT Cycle Month"/>
                        <RightOperand xsi:type="ValueRef" type="##PC4.0##76915825" name="Wholesale"/>
                    </Operand>
                </Operands>
            </Operand>
            <Operand xsi:type="LogicalExpression" expressionType="OR">
                <Operands>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##8537479" value="23102"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##8537479" value="21630"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##8537479" value="26201"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##8537479" value="23001"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##8537479" value="23203"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##8537479" value="20420"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##8537479" value="23207"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##6250817" value="21901"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##6250817" value="20416"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6250817" entity="Event" entityName="##PC4.0##67625472" attributeName="Provider ID"/>
                        <RightOperand xsi:type="Constant" type="##PC4.0##6250817" value="22004"/>
                    </Operand>
                </Operands>
            </Operand>
            <Operand xsi:type="LogicalExpression" expressionType="OR">
                <Operands>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6249415" entity="Event" entityName="##PC4.0##67625472" attributeName="Service filter"/>
                        <RightOperand xsi:type="ValueRef" type="##PC4.0##6249415" name="ROAMBL"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6249415" entity="Event" entityName="##PC4.0##67625472" attributeName="Service filter"/>
                        <RightOperand xsi:type="ValueRef" type="##PC4.0##6249415" name="ROAMGP"/>
                    </Operand>
                    <Operand xsi:type="Comparison" expressionType="EQ" type="Boolean">
                        <LeftOperand xsi:type="AttributeRef" type="##PC4.0##6249415" entity="Event" entityName="##PC4.0##67625472" attributeName="Service filter"/>
                        <RightOperand xsi:type="ValueRef" type="##PC4.0##6249415" name="GPRSRM"/>
                    </Operand>
                </Operands>
            </Operand>
        </Operands>
    </Condition>
</QualificationCriterion>

预期OutPut: -

  

NAME value1 value2 value4 iPass漫游区域1服务过滤器   伪允许和iPass漫游区域1最后BLIMPACT循环   月批发和iPass漫游1区iPass漫游   区域1提供商ID 23102或iPass漫游区域1提供商ID   21630或iPass漫游区域1提供商ID 26201或iPass   漫游区1提供商ID 23001或iPass漫游区1   提供商ID 23203或iPass漫游区1提供商ID 20420或   iPass漫游区1提供商ID 23207或iPass漫游区1   提供商ID 21901或iPass漫游区1提供商ID 20416或   iPass漫游区1提供商ID 22004或iPass漫游区1   iPass漫游区1服务过滤器ROAMBL或iPass漫游区   1服务过滤器ROAMGP或iPass漫游区1服务过滤器   GPRSRM OR

到目前为止我得到了什么,

  

NAME value1 value2 value3 value4 iPass漫游区1   和iPass漫游区域1服务过滤器iPass漫游   1区伪补丁iPass漫游区1最后   BLIMPACT周期月iPass漫游区1批发   iPass漫游区1或iPass漫游区1
  提供商ID iPass漫游区1 23102 iPass   漫游区1提供商ID iPass漫游区1   21630 iPass漫游区域1提供商ID iPass漫游   1区26201 iPass漫游区1提供商ID
  iPass漫游区1 23001 iPass漫游区1   提供商ID iPass漫游区1 23203 iPass   漫游区1提供商ID iPass漫游区1   20420 iPass漫游区1提供商ID iPass漫游   1区23207 iPass漫游区1提供商ID
  iPass漫游区1 21901 iPass漫游区1
  提供商ID iPass漫游区1 20416 iPass   漫游区1提供商ID iPass漫游区1   22004 iPass漫游区1或iPass漫游区1
  服务过滤器iPass漫游区1 ROAMBL
  iPass漫游区1服务过滤器iPass漫游区1   ROAMGP iPass漫游区域1服务过滤器iPass   漫游区1 GPRSRM

我的代码: -

SELECT xt.*
FROM   (select * from pc_element where element_type='QualificationCriterion' and name='ETDR Group' and first_effective_version is not null and last_effective_version is null) x,
       XMLTABLE('/QualificationCriterion/Condition | //Operand[not(@type="Boolean")] | //Operands/Operand/LeftOperand | //Operands/Operand/RightOperand'
         PASSING x.xmltype(element_value)
         COLUMNS
        -- "value0"    VARCHAR2(50) PATH '@expressionType',
           "value1"    VARCHAR2(50) PATH '@attributeName',
           "value2" varchar2(10) PATH '@name',
            "value3" varchar2(10) PATH '@value',
            "value4"    VARCHAR2(50) PATH '@expressionType'
         ) xt ; 

对于每个提取的值,我得到3个空格和连续的值请帮助,我是XML解析的新手,非常困惑,请帮助

1 个答案:

答案 0 :(得分:0)

以下是您需要的查询:

SELECT xt.NAME NAME, xt.attributeName value1, nvl(RName,RValue) value2, xt.expressionType value4
FROM   (select * from pc_element where element_type='QualificationCriterion' and name='ETDR Group' and first_effective_version is not null and last_effective_version is null) x,
   --XMLTABLE('/QualificationCriterion/Condition | //Operands/Operand[not(@type="Boolean")] | //Operands/Operand/LeftOperand | //Operands/Operand/RightOperand'
   XMLTABLE('//Operand[@type="Boolean"]' 
     PASSING x.xmltype(element_value)
     COLUMNS
       NAME   VARCHAR2(50) PATH './../../../../../@name',
       attributeName    VARCHAR2(50) PATH './LeftOperand/@attributeName',
       RName varchar2(50) PATH './RightOperand/@name',
        RValue varchar2(50) PATH './RightOperand/@value',
        expressionType    VARCHAR2(50) PATH './../../@expressionType'
        --"self"    varchar2(50) path 'name()'
     ) xt ;