Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORA-00932 (inconsistent datatypes: expected - got CLOB) error that I do not understand

Tags:

sql

oracle

I started out with a query as such:

    SELECT A.*
      FROM TABLE_A A
INNER JOIN TABLE_B B
        ON A.YEAR = B.YEAR
     WHERE A.ID IN (SELECT ID FROM TABLE_B)

The above query gave me duplicate records, so I added the DISTINCT keyword as such:

    SELECT DISTINCT A.*
      FROM TABLE_A A
INNER JOIN TABLE_B B
        ON A.YEAR = B.YEAR
     WHERE A.ID IN (SELECT ID FROM TABLE_B)

This second query gave me the following error:

ORA-00932: inconsistent datatypes: expected - got CLOB

  1. 00000 - "inconsistent datatypes: expected %s got %s"

I finally corrected the query and eliminated the duplicate records by moving the condition in the WHERE clause to the INNER JOIN like this:

    SELECT A.*
      FROM TABLE_A A
INNER JOIN TABLE_B B
        ON A.YEAR = B.YEAR
       AND A.ID = B.ID

I just don't understand why the second query did not work. Why does adding the DISTINCT keyword here suddenly cause an issue?

like image 330
Jake Avatar asked Apr 26 '17 14:04

Jake


People also ask

What does error ora-00932 mean?

ORA-00932: inconsistent datatypes: expected LONG BINARY got BLOB 0 PL/SQL: ORA-00932: inconsistent datatypes: expected - got CLOB

Why does Oracle return CLOB is not supported for column profiling?

ORACLE returns: This error occurs because CLOB is not a supported datatype when performing column profiling in Data Explorer. This is known issue and a feature request (IDE-5010) has been submitted to include the ability to profile CLOB datatype You could dump the data into a flat file or use datatype VARCHAR.

Is it possible to profile a CLOB datatype?

This is known issue and a feature request (IDE-5010) has been submitted to include the ability to profile CLOB datatype You could dump the data into a flat file or use datatype VARCHAR.

What is the difference between ora-00932 and xmlagg 2?

2 XMLAGG - ORA-00932: inconsistent datatypes: expected - got CLOB on CLOB 0 ORA-00932: inconsistent datatypes: expected LONG BINARY got BLOB


2 Answers

It's not a particularly enlightning error message, but it's because of the restrictions on LOBs, among which are:

  • You cannot specify LOB columns in the ORDER BY clause of a query, the GROUP BY clause of a query, or an aggregate function.

  • You cannot specify a LOB column in a SELECT... DISTINCT or SELECT... UNIQUE statement or in a join. However, you can specify a LOB attribute of an object type column in a SELECT... DISTINCT statement, a query that uses the UNION, or a MINUS set operator if the object type of the column has a MAP or ORDER function defined on it.

You're hitting the second of those, but the first comes up from time to time here too.

You can fake the same situation with something like:

SQL> select distinct col from (select to_clob('test') as col from dual);

ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got CLOB

You would be able to use distinct if you listed only non-CLOB columns, instead of using A.*, which is including a CLOB column from table_a.

You can work around this, but correcting the query to eliminate the duplicates was the right thing to do. Having to add distinct to a query is often a sign that something is wrong and you're fixing the symptoms rather than the cause.

like image 148
Alex Poole Avatar answered Oct 18 '22 20:10

Alex Poole


Solution is to use the function to_char() around each returned field, as Distinct/Group By/etc. cannot deal with a clob or even a substring of a clob.

like image 25
PaulK Avatar answered Oct 18 '22 21:10

PaulK