选择值是一行作为列值

时间:2014-12-14 08:41:37

标签: sql oracle-sqldeveloper

如何将行中的值检索为列值?

示例:

将以下查询的输出视为 INPUT

Select 1,2,3,4,5,6,7,8,9,10 
from dual;

我需要一个可以提供以下输出的查询:

COL1
----
 1
 2
 3
 4
 5
 6
 7
 8
 9
10

2 个答案:

答案 0 :(得分:0)

SELECT 1 AS "COL1" FROM dual
UNION
SELECT 2 FROM dual
UNION
SELECT 3 FROM dual
UNION
SELECT 4 FROM dual
UNION
SELECT 5 FROM dual
UNION
SELECT 6 FROM dual
UNION
SELECT 7 FROM dual
UNION
SELECT 8 FROM dual
UNION
SELECT 9 FROM dual
UNION
SELECT 10 FROM dual ;

答案 1 :(得分:0)

如果要在Oracle中生成一系列数字:

with n as (
      select level as n
      from dual
      connect by level <= 10 
     )
select *
from n;

或者,如果您有10列,则可以执行取消操作。一个简单的方法是union all

select col1 from t union all
select col2 from t union al
. . .
select col10 from t;