1
votes

I have run into a strange problem in an ALREADY WORKING code. There is a working procedure pkg_pbrer.p_gen_pbrer_rpt which returns v_po_report as an output cursor.

I am trying to capture this cursor into table_po_report_62 and this was working fine.

Now I am facing the error of

ORA-00932: inconsistent datatypes: expected - got -" in cursor fetch statement.

For simplicity of understanding, I have omitted the unnecessary lines of code.

DECLARE

  v_po_report SYS_REFCURSOR;

  TYPE type_po_report_62 IS RECORD (soc varchar2(1000), pt varchar2(1000), mp varchar2(1000), 
                                  blind varchar2(1000), ac varchar2(1000), placebo varchar2(1000));

  table_po_report_62 type_po_report_62; 
    --
    --
    -- Some working code
    --
    --


   -- Initializing Reference cursor    
    open v_po_report for 'select 1 from dual';

    pkg_pbrer.p_gen_pbrer_rpt (v_user_id,v_report_type,v_report_form_id,v_reg_report_id,v_po_report,v_po_case_list);

  LOOP
        FETCH v_po_report INTO table_po_report_62;
        -- Encountered ORA-00932: inconsistent datatypes: expected - got -
        EXIT WHEN v_po_report%NOTFOUND;
        insert into pbrer_output62_report (soc, pt, mp, blind, ac, placebo)
        values (table_po_report_62.soc, table_po_report_62.pt, table_po_report_62.mp, table_po_report_62.blind, table_po_report_62.ac, table_po_report_62.placebo) ;
  END LOOP;
    CLOSE v_po_report;

EXCEPTION
WHEN OTHERS THEN
   --
    --
    -- Some working code
    --
    -- 
END;
2
v_po_report is a refcursor which points to a single row dataset with a single column value 1, i.e. NUMBER data type. While you are trying to fetch into a record type with a completely different structure. - Lalit Kumar B

2 Answers

0
votes

Check your cursor data for recently added records which may be unconvertable for oracle. for exmaple a column accept varchar2 has value '1000' able to convert by oracle to a number but a value 'abc' do not.

0
votes

open v_po_report for 'select 1 from dual';

FETCH v_po_report INTO table_po_report_62;

v_po_report is a refcursor which points to a single row dataset with a single column value 1, i.e. NUMBER data type. While you are trying to fetch into a record type with a completely different structure.

You refcursor basically returns:

SQL> var v_po_report refcursor
SQL> declare
  2   v_po_report SYS_REFCURSOR;
  3  BEGIN
  4  OPEN :v_po_report FOR 'select 1 from dual';
  5  END;
  6  /

PL/SQL procedure successfully completed.

SQL> print v_po_report

         1
----------
         1

SQL>

So, with proper match of number of columns and data type, you could do it as:

SQL> DECLARE
  2    v_po_report SYS_REFCURSOR;
  3    TYPE type_po_report_62 IS RECORD (soc NUMBER);
  4    table_po_report_62 type_po_report_62;
  5  BEGIN
  6    OPEN v_po_report FOR 'select 1 from dual';
  7    LOOP
  8      FETCH v_po_report INTO table_po_report_62;
  9      EXIT WHEN v_po_report%NOTFOUND;
 10
 11      -- do something
 12
 13    END LOOP;
 14    CLOSE v_po_report;
 15  END;
 16  /

PL/SQL procedure successfully completed.

SQL>