代码之家  ›  专栏  ›  技术社区  ›  Bin Zhou

SQL:将count与Clob一起使用

  •  2
  • Bin Zhou  · 技术社区  · 10 年前

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

    由于同一个doc_id可能具有多个feature_vector值,因此我尝试使用以下方法获取计数:

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

    然而,我得到了一个错误,说

    ORA--00932数据类型不一致:应为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
    

    有人能解释一下幕后发生了什么吗?为什么不计算与生土块一起工作?

    1 回复  |  直到 9 年前
        1
  •  5
  •   mustaccio Gandalf    10 年前

    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