Tuesday, August 26, 2008

ORA-00932: inconsistent datatypes error

This seems to be Oracle 10g Bug , as per this bug number "4381035" if you fetch less field then what is contained in the SELECT list for CURSOR produces this error.

e.g.
PL/SQL used
.
CREATE OR REPLACE procedure TestCursor is
TYPE t_CurType is REF CURSOR;
c1 t_curtype;
v_SQLString VARCHAR2(50);
v_Deptno Number;
v_Dname VARCHAR2(20);
v_Loc VARCHAR2(10);
begin
v_SQLstring := 'select * from dept';
open c1 for v_SQLstring;
dbms_output.put_line('Before Fetch');
fetch c1 into v_Deptno;
dbms_output.put_line('v_Deptno = 'v_Deptno);
close c1;
end;


In the above example the Cursor uses "SELECT * FROM DEPT", but the FETCH command only fetches one of the fields when the "SELECT *..." actually returns 3 fields.

Diagnostic Analysis:
=====================
8i Database - Works
9i Database - Works
10g Database - Fails with the reported error
.
If the FETCH is modified to fetch all the columns (FETCH c1 into v_Deptno,
v_Dname, V_Loc;) then it works in 10g Database.

Workaround:
=============
Ensure the number of fields being Fetched matches the number of fields within
the Select list.
This is not a feasible workaround for the customer as they have too many
procedures and each procedure make a number of references to tables where a
"SELECT *..." is being used but only Fetching some of the fields.
Solution
To implement the solution, please execute the following steps:1. Provide the same number of define variables as columns in the SELECT statement.or2. Apply the patchset 10.2.0.4 and use the following event: alter session set events='10946 trace name context forever, level 4096';
or
3. Upgrade to 11.1 and use the following event:: alter session set events='10946 trace name context forever, level 4096';

No comments: