title: DBMS access denied when using DBMS
body: <p>As my title. I'm in trouble with this error. My code below:</p>
  <pre><code>create or replace PROCEDURE     TEST(
          P_CONTRACT VARCHAR2,
          p_result OUT SYS_REFCURSOR
  ) AS
  
  cursor_name INTEGER := DBMS_SQL.OPEN_CURSOR;
  ROWS_PROCESSED INTEGER ;
  v_string VARCHAR2(1000);
  
  BEGIN
      v_string:=' SELECT *
      FROM CONTRACT C 
      WHERE 1 = 1 ';
      
      IF(P_CONTRACT IS NOT NULL)  THEN
          v_string := v_string || ' AND C.CONTRACT_NAME = :P_CONTRACT ';
      END IF;
  
      v_string: = v_string || ' AND ROWNUM &lt;= 10';
  
      DBMS_SQL.PARSE(CURSOR_NAME,v_string,DBMS_SQL.NATIVE);
  
      IF  (P_CONTRACT IS NOT NULL) THEN
          DBMS_SQL.BIND_VARIABLE(CURSOR_NAME, ':P_CONTRACT', P_CONTRACT);         
      END IF;
  
      ROWS_PROCESSED := DBMS_SQL.EXECUTE(cursor_name);        
      p_result := DBMS_SQL.TO_REFCURSOR(cursor_name);
  
  EXCEPTION 
      WHEN OTHERS THEN 
          IF DBMS_SQL.IS_OPEN(cursor_name) THEN 
          DBMS_SQL.CLOSE_CURSOR(cursor_name); 
      END IF; 
  END ;
  </code></pre>
  <p>And I execute store like this:</p>
  <pre><code>set serveroutput on;
  VARIABLE p_result REFCURSOR ;
      Exec TEST('HNLT00014',:p_result);
  print p_result;
  </code></pre>
  <p>I've always got this error :</p>
  <pre><code>Error starting at line : 10 in command -
  BEGIN TEST('HNLT00014',:p_result); END;
  Error report -
  ORA-29471: DBMS_SQL access denied
  ORA-06512: at &quot;SYS.DBMS_SQL&quot;, line 1098
  ORA-06512: at &quot;TEST&quot;, line 6
  ORA-06512: at line 1
  29471. 00000 -  &quot;DBMS_SQL access denied&quot; 
  *Cause:    DBMS_SQL access was denied due to security concerns.
  *Action:   Check the alert log and trace file for more information.
  </code></pre>
  <p>I tried close and re-open newly established session like @Nick Krasnov recommended <a href="https://stackoverflow.com/questions/20690303/how-to-solve-ora-29471-on-dbms-sql-open-cursor">Link</a></p>
  <p>But it didn't work. Someone can help me? I'm using Oracle 12C.</p>
  <p>Thanks!</p>