使用Oracle XMLTABLE获取属性值

时间:2017-08-09 06:49:47

标签: oracle xmltable

<PivotSet>
<item>
<column name = "B">A</column>
<column name ="SUM(A)">24</column>
</item>
<item>
<column name = "B">B</column>
<column name = "SUM(A)">15</column>
</item>
<item>
<column name = "B">C</column>
<column name = "SUM(A)">18</column>
</item>
<item>
<column name = "B">D</column>
<column name = "SUM(A)">21</column>
</item>
</PivotSet>

我有这个XML专栏。我试图读取XML标签中的值

<column name = "B">A</column>

在SQL下面生成上面的XML。

select xmlserialize(content t.B_XML) from t_aa
pivot xml(
sum(A) for B in (any)
) t;

你可以帮我使用XMLTABLE SQL吗

1 个答案:

答案 0 :(得分:0)

select * from xmltable( '/PivotSet/item' passing xmltype('
<PivotSet>
<item>
<column name = "B">A</column>
<column name ="SUM(A)">24</column>
</item>
<item>
<column name = "B">B</column>
<column name = "SUM(A)">15</column>
</item>
<item>
<column name = "B">C</column>
<column name = "SUM(A)">18</column>
</item>
<item>
<column name = "B">D</column>
<column name = "SUM(A)">21</column>
</item>
</PivotSet>') columns 
  name varchar2(100) path 'column[@name eq "B" ]/text()', 
  sum  number path 'column[@name eq "SUM(A)" ]/number()')

或列位置

columns 
  name varchar2(100) path 'column[1]/text()', 
  sum  number path 'column[2]/number()'
  )