SQL:使用Clob计数

时间:2015-03-27 18:42:37

标签: sql oracle count clob

我有一个表feature_vector_t,其中包含两列doc_id和feature_vector,其中feature_vector是一个包含字符串的CLOB

由于相同的doc_id可能有多个feature_vector值,因此我尝试使用以下方法进行计数:

select doc_id, count(feature_vector) from feature_vector_t group by doc_id

但是,我收到了一个错误

  

ORA - 00932不一致的数据类型:expected-got CLOB   00932. 00000 - "数据类型不一致:预期%s获得%s"

另一个查询通过将Clob转换为字符串

来工作
select doc_id, count(dbms_lob.substr(feature_vector, 1, 5)) from feature_vector_t group by doc_id

有人可以解释一下幕后发生了什么吗?为什么不计算使用raw clob?

1 个答案:

答案 0 :(得分:4)

似乎Oracle有一个限制,不允许您将LOB传递给COUNT()函数。

但是,出于性能原因,您还不想计算LOB。如果feature_vector永远不是NULL,那么就是一个简单的

select doc_id, count(*) from feature_vector_t group by doc_id 

应该足够了,否则你可以使用这样的东西:

select 
 doc_id, 
 count(case when feature_vector is null then null else 1 end) 
from feature_vector_t group by doc_id