【发布时间】:2014-03-21 22:01:08
【问题描述】:
我正在尝试创建一个复杂的选择查询,它使用如下临时表和语法
with as
table1
( select start_date, end_date ....somequery - returns only 1 row ),
table2
( select ... somequery use table1 columns in where clause.. ),
table3
( select ... use table1 columns in where clause .. )
select * from
select case when ( start_date < sysdate -1000 and end_date > sysdate ) then 'table2' else 'table3' end from table1
where rownum < 10
所以逻辑很简单,基于表 1 的返回值,我可能想查询表 2 或可能想查询表 3
问题:Oracle不允许在sql查询中动态生成表名
我知道我可以编写一个程序并使用 EXECUTE IMMEDIATE,但由于某种原因,我必须通过单个查询来完成所有事情。任何帮助将不胜感激。
【问题讨论】: