水平显示多个Select语句结果

时间:2014-10-05 14:28:33

标签: sql oracle

数据库版本:Oracle 11.1.2.1.0 操作系统:OEL5

我正在尝试使用SQL水平打印多个SELECT语句的结果,但无法实现我想要的结果。

多个SQL:

SELECT 'DB Version', version db_version FROM v$instance
UNION ALL
select 'Oracle Client', length(addr)*4 || '-bits' word_length from v$process where ROWNUM =1
UNION ALL
/

结果:

'DBVERSION'            DB_VERSION  
 ---------------------- ----------------------------------------------------------------------------  
 DB Version             11.2.0.1.0  
 Oracle Client          64-bits  

期望的结果:

DB VERSION  ORACLE CLIENT   
--------    ------------------ 
11.2.0.1.0  64-bits         

2 个答案:

答案 0 :(得分:1)

现在正在进行中,假设我们正在谈论所需的结果只是一行有几列:

select max(case when col = col1 then colval end) as "DB VERSION",
       max(case when col = col2 then colval end) as "ORACLE CLIENT"
  from (SELECT version colval, 'col1' col
          FROM v$instance
        UNION ALL
        select length(addr) * 4 || '-bits',
               'col2'
          from v$process
         where ROWNUM = 1)

答案 1 :(得分:1)

如果您知道每个子查询返回一行,则可以使用cross join或子选择:

SELECT (SELECT version db_version FROM v$instance) as "DB Version",
       (select length(addr)*4 || '-bits' word_length from v$process where ROWNUM = 1) as "Oracle Client"

或:

SELECT v."DB Version", oc."Oracle Client"
FROM (SELECT version db_version as "DB Version" FROM v$instance) v CROSS JOIN
     (select length(addr)*4 || '-bits' as "Oracle Client" from v$process where ROWNUM = 1)  oc