title: Invalid Cursor when Passing RefCursor to a function
body: <p>I am trying to execute a function that receives a REFCURSOR and performs some data manipulation.</p>
  
  <p>To test my function I have this SQL/PLUS code:</p>
  
  <pre><code>var some_cursor REFCURSOR;
  
  exec :some_cursor := SCHEMA.test_getcursor;
  
  print some_cursor;
  
  variable res varchar2;
  
  exec :res := SCHEMA.second_function(:some_cursor, 'Other_parameter');
  
  print res;  
  </code></pre>
  
  <p>Now, the first <code>test_getcursor</code> function is a simple function that OPENS the cursor, performs a select query and returns the cursor. It works just fine and it prints <code>some_cursor</code> just fine too.</p>
  
  <p>The problem happens when I call the <code>second_function</code> and pass the refcursor to it.</p>
  
  <p>Function has the following code:</p>
  
  <pre><code>type cursor_row
  IS RECORD
  (field_1 some_field1%type,
   field_2 some_field2%type,
   field_3 some_field3%type);
  
   new_row cursor_row;
  
  BEGIN
  LOOP
  fetch PASSED_IN_REFCURSOR INTO new_row --this is where the function fails
  ...data manipulation...
  EXIT WHEN PASSED_IN_REFCURSOR%NOTFOUND;
  END LOOP;
  CLOSE PASSED_IN_REFCURSOR;
  END;
  </code></pre>
  
  <p>The error I am getting is <code>Invalid Cursor</code>.</p>
  
  <p>I am sure that the type I created has the same number of rows and the same data types as the ref cursor.</p>
  
  <p>What am I doing wrong in this case? I am using Oracle 10g, PL/SQL 10.2</p>