I stuck in one problem and I have no idea what to do. In my table I have column type CLOB and in my SELECT
I use this column and I can not remove from select statement.
Somehow I try to change it to VARCHAR(255) but my table contains data and backup table and again restore will take me time. So far here is my SELECT query:
SELECT * FROM
(SELECT a.*,
df.Name AS PaymentTypeName
FROM ata a
INNER JOIN debitform df ON a.PaymentType = df.Id
WHERE a.Deviation = '1'
AND a.ProjectID = 141
AND a.ParentAta = '0'
AND TYPE = 1
UNION
SELECT a.*,
df.Name AS PaymentTypeName
FROM ata a
INNER JOIN debitform df ON a.PaymentType = df.Id
WHERE a.Deviation = '1'
AND a.ProjectID = 141
AND a.ParentAta = '0'
AND TYPE = 0
AND a.BecomeExternalAtaFromInternal = 1) a
This gives error:
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got clob
Any suggestion and comment what to do to eliminate this kind of errors.
You are getting this error because of the UNION clause. UNION implements a distinct sort operation, and we can't do those on CLOBs.
Simplest option is to change to UNION ALL. This could theoretically introduce duplicates into the final result set, although it would seem unlikely given the WHERE criteria for each subquery.
Alternatively it looks as though you can do away with the UNION altogether, by re-writing your query like this:
SELECT * FROM
(SELECT a.*,
df.Name AS PaymentTypeName
FROM ata a
INNER JOIN debitform df ON a.PaymentType = df.Id
WHERE a.Deviation = '1'
AND a.ProjectID = 141
AND a.ParentAta = '0'
AND (TYPE = 1
OR (TYPE = 0
AND a.BecomeExternalAtaFromInternal = 1)
)
)a
This approach might be more efficient.