oracle 使用带有联合和 CLOB 字段的选择时出现 ORA-00932 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17732302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:48:11  来源:igfitidea点击:

Error ORA-00932 when using a select with union and CLOB fields

databaseoracleplsql

提问by gabsferreira

First of all, this isn't a duplicate of thisquestion. If it is, sorry but I couldn't solve my problem by reading it.

首先,这不是这个问题的重复。如果是,对不起,我无法通过阅读来解决我的问题。

I'm getting this error:

我收到此错误:

ORA-00932: inconsistent datatypes: expected - got CLOB

When I try to execute this SELECT statement:

当我尝试执行此 SELECT 语句时:

SELECT TXT.t_txt 
  FROM CITADM.tb_avu_txt_grc GR  
 INNER JOIN CITADM.tb_avu_txt TXT   
    ON (GR.e_txt = TXT.e_txt and GR.u_txt = TXT.u_txt)  
 WHERE  TXT.u_lin_ord = 1
UNION
SELECT TXT.t_txt 
  FROM CITADM.tb_avu_txt_grc_cvd GRC  
 INNER JOIN CITADM.tb_avu_txt TXT  
    ON (GRC.e_txt = TXT.e_txt and GRC.u_txt = TXT.u_txt)  
 WHERE  TXT.u_lin_ord = 2

The selected field(t_txt) is of CLOB datatype. As you can see, it's the same column of the same table. This statement belongs to a bigger one, I've isolated the part where I'm having this problem.

所选字段(t_txt) 是CLOB 数据类型。如您所见,它是同一个表的同一列。这个声明属于一个更大的声明,我已经隔离了我遇到这个问题的部分。

Thank you very much.

非常感谢。

回答by Eric Petroelje

I believe the problem is the use of UNIONinstead of UNION ALL. The UNIONoperator will combine the two sets and eliminate duplicates. Since CLOB types cannot be compared, the duplicate elimination part is not possible.

我相信问题是使用UNION而不是UNION ALL. 该UNION运营商将结合两套和消除重复。由于无法比较 CLOB 类型,因此无法进行重复消除部分。

Using UNION ALLwon't attempt to do duplicate elimination (you probably don't have duplicates anyways) so it should work.

UsingUNION ALL不会尝试进行重复消除(您可能无论如何都没有重复)所以它应该可以工作。

回答by Friedrich

As I hadduplicates, I couldn't use UNION ALL. This solution work perfectly, thank you!

由于我重复项,我无法使用 UNION ALL。此解决方案完美运行,谢谢!

BTW: This is imho the only correct answer, because UNION ALL and UNION are semantically different. If don't have duplicates at all, using UNION imposes an unnecessary sort overhead.

顺便说一句:恕我直言,这是唯一正确的答案,因为 UNION ALL 和 UNION 在语义上是不同的。如果根本没有重复项,则使用 UNION 会带来不必要的排序开销。