如何在Oracle中将多列转换为一列

时间:2013-07-04 10:38:51

标签: sql oracle

我的结果如下:

level_1_node level_2_node level_3_node level_4_node 
Node 1       Node2        Node 3       Node 4

我想将其转换为:

Node
Node 1
Node 2
Node 3
Node 4

怎么做?

2 个答案:

答案 0 :(得分:3)

您可以使用 Union

select "level_1_node" as Node from Table1
union
select "level_2_node" as Node from Table1
union
select "level_3_node" as Node from Table1
union
select "level_4_node" as Node from Table1

<强> SQL Fiddle

答案 1 :(得分:3)

使用unpivot表格运算符:

select value
from tablename
unpivot 
(
  value
  for node in (level_1_node, 
               level_2_node, 
               level_3_node, 
               level_4_node)
);