title: PL/SQL: ORA-00942: table or view does not exist. Inside Function
body: <p>I can view the result when I write the query outside the block but writing it inside function shows an error.</p>
  
  <pre><code>SELECT max(logid) FROM hawk.log_patch_execution_result;
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>461
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION latest_log_id RETURN NUMBER IS
  v_log_id NUMBER; 
  v_sql VARCHAR2(4000);
  BEGIN
    SELECT max(logid) INTO v_log_id FROM hawk.log_patch_execution_result;
    RETURN v_log_id;
  END latest_log_id;
  /
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Create function, executed in 16 ms
  PL/SQL: ORA-00942: table or view does not exist
  PL/SQL: SQL Statement ignored
  Total execution time 16 ms
  </code></pre>