Oracle XE 11. a very simple join query gave me the following error:
ORA-00932: inconsistent datatypes: expected - got CLOB
Tables:
Product
----------------------------------
id, name, description, categoryId
Catetory
------------------
id, name
The product description is CLOB.
SQL> desc Product;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER(19)
NAME NOT NULL VARCHAR2(30 CHAR)
CATEGORYID NUMBER(19)
DESCRIPTION CLOB
SQL> desc Category;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER(19)
NAME NOT NULL VARCHAR2(30 CHAR)
Query:
SELECT DISTINCT t1.ID, t1.DESCRIPTION, t1.NAME, t0.name FROM Product t1
LEFT OUTER JOIN Category t0 ON (t0.ID = t1.categoryId);
ERROR at line 1: ORA-00932: inconsistent datatypes: expected - got CLOB
IF I remove the t0.name from selection, it will work. weird.
SELECT DISTINCT t1.ID, t1.DESCRIPTION, t1.NAME FROM Product t1
LEFT OUTER JOIN Category t0 ON (t0.ID = t1.categoryId);
Thanks.
You cannot specify LOB columns in the ORDER BY clause of a query, or in the GROUP BY clause of a query or in an aggregate function. To get around this you can to_char the column if it's < 4000 characters and substr it if it's longer. "there is no reason for it to be present in the GROUP BY list."
The CLOB data type stores any kind of text data in random-access chunks, called sbspaces. Text data can include text-formatting information, if this information is also textual, such as PostScript, Hypertext Markup Language (HTML), Standard Graphic Markup Language (SGML), or Extensible Markup Language (XML) data.
To correct this error, you can do one of the following: Not use Oracle functions in your SQL (against the LONG datatype field). Consider modifying your table so that the supplier_name field is either a VARCHAR2 or CHAR field. Try writing a custom PLSQL function to convert a LONG to a VARCHAR2.
A CLOB (character large object) value can be up to 2,147,483,647 characters long. A CLOB is used to store unicode character-based data, such as large documents in any character set.
The DISTINCT
keyword cannot be used for CLOB
datatypes.
The workaround is :
SELECT a.*
, b.clob
FROM (SELECT DISTINCT
... /* columns list wihtout clob columns */
FROM ...
) a
JOIN
table_with_clobs b
ON ...
Going to your sample it would be:
SELECT Po.ID, Po.DESCRIPTION, Po.NAME, PC.CatName
FROM
( SELECT DISTINCT t1.ID, t0.name CatName
FROM Product t1
LEFT OUTER JOIN Category t0
ON t0.ID = t1.categoryId
) PC
join Product PO
on PO.ID = PC.ID
If your clob column does not contain more than 4000 characters, you could try this..
SELECT DISTINCT t1.ID, to_char(t1.DESCRIPTION), t1.NAME FROM Product t1
LEFT OUTER JOIN Category t0 ON (t0.ID = t1.categoryId);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With