title: Oracle Select query with dynamic table name
body: <p>I m trying to create a complicated select query which uses temp tables and syntax as below</p>
  
  <pre><code>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 &lt; sysdate -1000 and end_date &gt; sysdate ) then 'table2' else 'table3' end  from table1 
           where rownum &lt; 10
  </code></pre>
  
  <p>So logic is simple based on return value from table1 i may want to query table 2 or may want to query table3</p>
  
  <p>Problem: Oracle doesnt allow table name to be dynamically generated in a sql query</p>
  
  <p>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.</p>