title: How to use CASE statement in FROM Clause to decide which table to be used for fetching data in Oracle?
body: <p>I have two tables , HISTORY_DATA and CURRENT_DATA , I have an input parameter REPORT_DATE ,as per following  Condition , I have to fetch data :</p>
  <pre><code>IF(REPORT_DATE&lt;=TRUNC(SYSDATE-40))THEN
           SCHD_TABLE:='HISTORY_DATA' ;
           ELSE
           SCHD_TABLE:='CURRENT_DATA';  
           END IF ; 
  </code></pre>
  <ol>
  <li><p>I tried using dynamic SQL , but it is giving error as invalid table name .</p>
  <pre><code>SELECT * FROM ''||SCHD_TABLE||'' ;
  </code></pre>
  </li>
  <li><p>Used CASE STATEMENT but it also gave Syntax error :</p>
  <pre><code>SELECT * FROM (CASE WHEN REPORT_DATE&lt;=TRUNC(SYSDATE-40) THEN HISTORY_DATA 
                      ELSE CURRENT_DATA 
                 END)
  </code></pre>
  </li>
  </ol>
  <p>Please guide how to resolve this .</p>