将Pivot xml输出转换为不带xml

时间:2017-03-17 07:42:45

标签: oracle oracle11g pivot pivot-xml

我有以下表格:

 ID | Key | Value
 --   ---   -----
 1     A     aa    
 2     B     bb
 3     A     ay
 4     C     cc
 5     B     bx
 6     C     ct 

我需要输出:

A    B    C
---  ---  ---
aa   bb   cc
ay   bx   ct

当我使用带有子查询的PIVOT时,它不起作用:

Select * from (Select Key, Value, Id from tableName
pivot (max(Value) for Key IN (SELECT distinct Key from tableName)));

如果我使用PIVOT xml,子查询可以工作:

Select * from (Select Key, Value, Id from tableName)
pivot xml (max(Value) for Key IN (SELECT distinct Key from tableName));

但是当使用PIVOT xml时,我得到xml格式的输出:

 A                      B    C
---                    ---  ---
<PivotSet><item...aa   ...   ...

如何在没有xml标签的情况下将其转换为表格输出?任何帮助将不胜感激。谢谢!

0 个答案:

没有答案