Oracle SQL 根据 blob 字段中的值分组

Oracle SQL grouping based on value in blob field

这可能是不可能的

我有一个 table 和一个包含 XML 的 blob,我想根据 blob 的内容得到一个计数有没有办法在一个查询中完成而不是做

select count(*)
from MyTable
where dbms_lob.instr(bitstream, utl_raw.CAST_TO_RAW('ObjA'), 1, 1) > 0

select count(*)
from MyTable
where dbms_lob.instr(bitstream, utl_raw.CAST_TO_RAW('ObjB'), 1, 1) > 0

select count(*)
from MyTable
where dbms_lob.instr(bitstream, utl_raw.CAST_TO_RAW('ObjC'), 1, 1) > 0

select count(*)
from MyTable
where dbms_lob.instr(bitstream, utl_raw.CAST_TO_RAW('ObjD'), 1, 1) > 0

select count(*)
from MyTable
where dbms_lob.instr(bitstream, utl_raw.CAST_TO_RAW('ObjE'), 1, 1) > 0

这样的东西行吗?

将您要查找的值存储到 CTE 中,然后将该 CTE 加入您的 table。

WITH
   temp (obj)
   AS
      (SELECT *
         FROM TABLE (sys.odcivarchar2list ('ObjA',
                                           'ObjB',
                                           'ObjC',
                                           'ObjD',
                                           'ObjE')))
  SELECT t.obj, COUNT (*)
    FROM mytable e
         JOIN temp t
            ON DBMS_LOB.INSTR (bitstream,
                               UTL_RAW.cast_to_raw (t.obj),
                               1,
                               1) > 0
GROUP BY t.obj;