title: PL/SQL: Fetching from a Cursor that is passed between two functions
body: <p>I have a quick question about fetching results from a weakly typed cursor and was wondering if anyone had come across this problem before?</p>
  
  <p>My set up is as follows;</p>
  
  <p>Inner function;</p>
  
  <pre><code>create or replace FUNCTION A_CURSOR_TEST_INNER
  (
    varCursor OUT SYS_REFCURSOR
  )
  RETURN NUMBER
  AS
    varStatus NUMBER;
  BEGIN
    OPEN varCursor  FOR
    SELECT docid
    FROM DOCUMENT_TABLE;
  
    RETURN 0;
  END;
  </code></pre>
  
  <p>Calling function;</p>
  
  <pre><code>create or replace FUNCTION A_CURSOR_TEST_OUTER
  (
    varCursor  OUT SYS_REFCURSOR
  )
  RETURN NUMBER
  AS
    varStatus NUMBER;
  BEGIN
    varStatus := A_CURSOR_TEST_INNER(varCursor  =&gt; varCursor);
    RETURN 0;
  END;
  </code></pre>
  
  <p>Test harness code;</p>
  
  <pre><code>DECLARE
    varCursor  SYS_REFCURSOR;
    v_Return NUMBER;
  BEGIN
    v_Return := A_CURSOR_TEST_OUTER(varCursor  =&gt; varCursor);
      DECLARE
          docid_ NUMBER;
      BEGIN
          IF(varCursor %ISOPEN) THEN
              LOOP
                  FETCH varCursor  INTO docid_ ;
                  EXIT WHEN varCursor %NOTFOUND;
                  DBMS_OUTPUT.PUT_LINE(' docid_:' || docid_ );
              END LOOP;
              CLOSE varCursor ;
          END IF;
      END;
  END;
  </code></pre>
  
  <p>The error I get if I run my test harness code is;</p>
  
  <blockquote>
    <p>ORA-06504: PL/SQL: Return types of
    Result Set variables or query do not
    match</p>
  </blockquote>
  
  <p>I'm not really sure what is causing this to occur. The error is happening in my test code, but I've used this exact same method hundreds of times before and not encountered this problem. The only difference now being, that the cursor is being passed back up through two functions instead of just one.</p>
  
  <p>Does anyone have any idea what the problem might be here? I've Googled around for it and all I can find are suggestions to strongly type the cursors, which is not an option for me unfortunately.</p>
  
  <p>Thanks for any help anyone can give, cheers.</p>