title: Referring a to generic cursor in an anonymous block in oracle
body: <p>In a package <code>pkg_cost_api</code> the following is defined.</p>
  
  <pre><code>TYPE t_ref_generic              IS REF CURSOR;
  </code></pre>
  
  <p>Below is a procedure in the same package.</p>
  
  <pre><code>PROCEDURE transfer_costs
  
  (
  
          p_source_isbn             IN product_header.mhid_part_nbr%TYPE,
          p_dest_isbn               IN product_header.mhid_part_nbr%TYPE,
          p_plant_mfg_flag          IN VARCHAR2,
          p_employee_number         IN product_header.add_by%TYPE,
          p_transfer_results        OUT pkg_cost_api.t_ref_generic
  ) IS
  
          v_gen_cost_rec                  t_gen_cost_record := t_gen_cost_record(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  
          v_result_set                    t_gen_cost_table := t_gen_cost_table();
  BEGIN
          -- relevant code
          Loop
  
                  v_gen_cost_rec.initialize();
                  v_gen_cost_rec.gen_cost_code := 'some value';
                  v_gen_cost_rec.gen_cost_code_desc := 'some value';
                  v_gen_cost_rec.amount := 'some value';
                  v_result_set.EXTEND;
                  v_result_set(v_result_set.COUNT) := v_gen_cost_rec;
  
          End Loop;
  
         OPEN p_transfer_results FOR
  
         SELECT *
                 FROM TABLE(CAST(v_result_set AS t_gen_cost_table)) gen_costs;
  
  END;
  </code></pre>
  
  <p>And the type t_gen_cost_record is:</p>
  
  <pre><code>CREATE OR REPLACE TYPE t_gen_cost_record AS
  OBJECT
  
  (
  
      gen_cost_code      VARCHAR2(30),
      gen_cost_code_desc VARCHAR2(100),
      amount             NUMBER,
      cost_code          VARCHAR2(30),
      acct_category_code VARCHAR2(30),
      category_desc      VARCHAR2(100),
      category_code      VARCHAR2(30),
      oracle_task_code   VARCHAR2(3),
      MEMBER PROCEDURE initialize
  );
  </code></pre>
  
  <p>I'm trying to run this below script.</p>
  
  <pre><code>DECLARE
  
      c_transfer_results          pkg_cost_api.t_ref_generic;
  
      v_finance_source_note       product_note.note%TYPE;
      v_comments                  nopc.comments%TYPE;
      v_dest_comments             nopc.comments%TYPE;
  
      v_nopc_isbn                 nopc.isbn%TYPE := '0077449835';
      v_move_plant_flag           nopc.move_plant_flag%TYPE;
      v_move_to_isbn              nopc.move_to_isbn%TYPE := '0077364678';
  
      v_gen_cost_code         VARCHAR2(30);
      v_gen_cost_code_desc    VARCHAR2(100);
      v_amount                NUMBER;
  
  
  BEGIN
  
   pkg_cost_api.transfer_costs(
  
                      p_source_isbn =&gt; v_nopc_isbn,
                      p_dest_isbn =&gt; v_move_to_isbn,
                      p_plant_mfg_flag =&gt; 'PLANT',
                      p_employee_number =&gt; '000159457',
                      p_transfer_results =&gt; c_transfer_results
                  );
              v_dest_comments := Chr(10) || ' Note Date: ' || SYSDATE;
              v_finance_source_note := Chr(10) || ' Note Date: ' || SYSDATE;
  
              LOOP
              FETCH c_transfer_results INTO v_gen_cost_code, v_gen_cost_code_desc, v_amount;
  
                  EXIT WHEN c_transfer_results%NOTFOUND;
  
                  v_comments := v_comments || CHR(10) || 'Plant Transfer from ' ||  v_nopc_isbn || ' to ' || v_move_to_isbn ||
                              ' Amounts: ' || v_gen_cost_code_desc || ': ' || v_amount || CHR(10);
  
                  v_finance_source_note := v_finance_source_note || CHR(10) || 'Plant Transfer from ' || v_nopc_isbn || ' to ' || v_move_to_isbn ||
                              ' Amounts: ' || v_gen_cost_code_desc || ': ' || v_amount || CHR(10);
  
                  v_dest_comments := v_dest_comments || CHR(10) ||
                              'Plant Transfer to ' || v_move_to_isbn || ' from ' || v_nopc_isbn ||
                              ' Amounts: ' || v_gen_cost_code_desc || ': ' || v_amount || CHR(10);
  
              END LOOP;
  
  EXCEPTION
  
    WHEN OTHERS THEN
  
     RAISE;
  
  END;
  </code></pre>
  
  <p>When I try to run the above standalone script I get the following error:</p>
  
  <pre><code>Error report:
  ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
  ORA-06512: at line 39 06504. 00000 - "PL/SQL: Return types of Result Set variables or query do not match"
  *Cause: Number and/or types of columns in a query does not match declared return type of a result set variable, or declared types of two Result Set variables do not match.
  *Action: Change the program statement or declaration. Verify what query the variable actually refers to during execution.
  </code></pre>
  
  <p>Can please someone tell me what exactly am I doing wrong here.</p>