我正在尝试使用Oracle /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 :-
名称: 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或
到现在为止我所拥有的,
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
我的守则:-
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解析方面的新手,非常困惑,请帮助。
发布于 2016-10-02 19:41:18
下面是您需要的查询:
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 ;
https://stackoverflow.com/questions/39720616
复制相似问题