title: Oracle Function return varchar2 is ok, but return SYS_REFCURSOR get ORA-14551
body: <p>Tool: Toad 9.7.2.5</p>
  
  <p>I wrote 1 function which has an insert statement in it.</p>
  
  <p>I execute command </p>
  
  <pre><code>SELECT TWO2F_QUERY_TEST ('XX', 'XX') 
    FROM DUAL;
  </code></pre>
  
  <p>When this function, which return <code>SYS_REFCURSOR</code>, I will get</p>
  
  <blockquote>
    <p>1, N, *INSERT TWO2R063_W1 ERROR(C1-NOT USED)**ORA-14551: cannot
    perform a DML operation inside a query</p>
  </blockquote>
  
  <p>When this function, which returns <code>varchar2</code>, it will process successful</p>
  
  <p>Code : </p>
  
  <pre><code>CREATE OR REPLACE FUNCTION TWO2F_QUERY_TEST
  (PI_BUS_ID         IN  VARCHAR2 ,
   PI_TMNL_ID        IN  VARCHAR2 
  )RETURN SYS_REFCURSOR IS
  --)RETURN VARCHAR2 IS
  PO_CURSOR SYS_REFCURSOR;
  WK_ACTION VARCHAR2(01) := 'Y';
  WK_MSG    VARCHAR2(100);
  BEGIN
    BEGIN
      INSERT INTO TWO2R063_W1
        ( R063W1_TITLE   ,
          R063W1_FORWARD
        )
      VALUES             
        ( 'PROGRAM NOT USED' ,
          'XX'            
        )
      ;
    EXCEPTION
      WHEN OTHERS THEN
        WK_ACTION := 'N';
        WK_MSG    := SUBSTR('*INSERT TWO2R063_W1 ERROR(C1-NOT USED)'||SQLERRM, 1, 100);
        GOTO OUTER;
    &lt;&lt;OUTER&gt;&gt; 
    &lt;&lt;ENDRTN&gt;&gt;                                   
  
    OPEN PO_CURSOR FOR 
      SELECT ROWNUM    AS PO_ROWNUM ,
             WK_ACTION AS PO_ACTION , 
             WK_MSG    AS PO_MSG   
        FROM DUAL
      ;
  
    RETURN PO_CURSOR;
  
    --RETURN 'Y';
  
  END TWO2F_QUERY_TEST;
  
  /
  SHOW ERROR;
  DROP    PUBLIC  SYNONYM TWO2F_QUERY_TEST;
  CREATE  PUBLIC  SYNONYM TWO2F_QUERY_TEST FOR TWO2F_QUERY_TEST;
  GRANT   EXECUTE ON TWO2F_QUERY_TEST TO GTS_AP_MAINTAIN, EGTS;
  /
  
  ========================================================
  DROP TABLE TWO2.TWO2R063_W1 CASCADE CONSTRAINTS;
  
  CREATE GLOBAL TEMPORARY TABLE TWO2.TWO2R063_W1
  (R063W1_TITLE   VARCHAR2(50 BYTE),
   R063W1_FORWARD VARCHAR2(20 BYTE)
  )ON COMMIT PRESERVE ROWS NOCACHE;
  
  DROP PUBLIC SYNONYM TWO2R063_W1;
  CREATE PUBLIC SYNONYM TWO2R063_W1 FOR TWO2.TWO2R063_W1;
  GRANT DELETE, INSERT, SELECT, UPDATE ON TWO2.TWO2R063_W1 TO TWO2_MAINTAIN;
  GRANT SELECT ON TWO2.TWO2R063_W1 TO TWO2_QUERY;
  </code></pre>