I m trying to create a complicated select query which uses temp tables and syntax as below
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
So logic is simple based on return value from table1 i may want to query table 2 or may want to query table3
Problem: Oracle doesnt allow table name to be dynamically generated in a sql query
I know i can write a procedure and use EXECUTE IMMEDIATE but for some reason i have to do everything via a single query. Any help will be greatly appreciated.