SQL: 使用 Clob 计数
SQL: use count with Clob
我有一个包含两列 doc_id 和 feature_vector 的 table feature_vector_t,其中 feature_vector 是一个包含字符串的 CLOB
。
由于相同的 doc_id 可能有多个 feature_vector 值,我正在尝试使用以下方法获取计数:
select doc_id, count(feature_vector) from feature_vector_t group by doc_id
但是,我收到一条错误消息
ORA--00932 inconsistent datatypes:expected-got CLOB
00932. 00000-"inconsistent datatypes: expected %s got %s"
另一个查询通过将 Clob 转换为字符串来工作
select doc_id, count(dbms_lob.substr(feature_vector, 1, 5)) from feature_vector_t group by doc_id
谁能解释一下幕后发生的事情?为什么计数不能与原始 clob 一起使用?
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
我有一个包含两列 doc_id 和 feature_vector 的 table feature_vector_t,其中 feature_vector 是一个包含字符串的 CLOB
。
由于相同的 doc_id 可能有多个 feature_vector 值,我正在尝试使用以下方法获取计数:
select doc_id, count(feature_vector) from feature_vector_t group by doc_id
但是,我收到一条错误消息
ORA--00932 inconsistent datatypes:expected-got CLOB 00932. 00000-"inconsistent datatypes: expected %s got %s"
另一个查询通过将 Clob 转换为字符串来工作
select doc_id, count(dbms_lob.substr(feature_vector, 1, 5)) from feature_vector_t group by doc_id
谁能解释一下幕后发生的事情?为什么计数不能与原始 clob 一起使用?
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