日期:2014-05-17  浏览次数:20848 次

请教将多个结果同时显示出来的 Sql 语句
key_table1_ID,   key_table2_ID,   key_table3_ID   是   Oracle   中的   sequence

select   'Table1 '   as   Table_Name,   (select   max(Table1_ID)   from   Table1)   as   MAX_ID,   Key_Table1_ID.Nextval   as   PrimaryKey_NextValue     from   DUAL;  
select   'Table2 '   as   Table_Name,   (select   max(Table2_ID)   from   Table2)   as   MAX_ID,   Key_Table2_ID.Nextval   as   PrimaryKey_NextValue     from   DUAL;  
select   'Table3 '   as   Table_Name,   (select   max(Table3_ID)   from   Table3)   as   MAX_ID,   Key_Table2_ID.Nextval   as   PrimaryKey_NextValue     from   DUAL;  
...

有什么办法将这些   Sql   语句的查询结果显示为如下形式   ?

Table_Name     Max_ID           PrimaryKey_NextValue  
-------------------------
Table1             30                     100
Table2             40                     200
Table3             50                     300
...



------解决方案--------------------
实在不行就用union。
select 'Table1 ' as Table_Name, (select max(Table1_ID) from Table1) as MAX_ID, Key_Table1_ID.Nextval as PrimaryKey_NextValue from DUAL
union
select 'Table2 ' as Table_Name, (select max(Table2_ID) from Table2) as MAX_ID, Key_Table2_ID.Nextval as PrimaryKey_NextValue from DUAL;
union
select 'Table3 ' as Table_Name, (select max(Table3_ID) from Table3) as MAX_ID, Key_Table2_ID.Nextval as PrimaryKey_NextValue from DUAL;
------解决方案--------------------
除了楼上的,没想到更好的方法
------解决方案--------------------
把Key_Table2_ID.Nextval后2个替换掉,自己手动+

就象
i++(怎么写的,就是那个编译器不同造成的结果不同)