繁体   English   中英

如何在 BLOB 字段中进行文本搜索

[英]How to text search in BLOB field

我们创建了一个 BLOB 类型列来存储 6000 到 7000 个 ASCII 字符的有效负载。 我正在使用以下代码插入有效负载。

PreparedStatement stmt=conn.prepareStatement(insertQuery);
String record="My ASCII Payload";
stmt.setBytes(1, record.getBytes());
stmt.execute();

当我在查询下运行时,我可以看到 output 中的字符长度。

select dbms_lob.getLength(MY_PAYLOAD)
  from RAW_DATA;

6085

我想在这个 BLOB 列中执行文本搜索,我尝试了以下选项,但没有任何效果。 在 BLOB 列中执行文本搜索的正确方法是什么?

SELECT * FROM RAW_DATA t
WHERE dbms_lob.instr(t.MY_PAYLOAD,utl_raw.cast_to_raw(‘1234’))>0



select *
       from RAW_DATA 
       where dbms_lob.instr (MY_PAYLOAD, -- the blob
                       utl_raw.cast_to_raw ('1234'),
                       1, -- where to start. i.e. offset
                       1 -- Which occurrance i.e. 1=first
                        ) > 0 

您可以在 blob 上创建文本索引,只要它们包含文本(自然)

SQL> create table t ( x int, b blob);

Table created.

SQL>
SQL> insert into t values ( 1, utl_raw.cast_to_Raw('Hello there'));

1 row created.

SQL> insert into t values ( 2, utl_raw.cast_to_Raw('Goodbye tomorrow'));

1 row created.

SQL>
SQL> create index t_ix on t ( b )
  2  indextype is ctxsys.context;

Index created.

SQL>
SQL> select x
  2  from t where contains(b,'Hello') > 0;

         X
----------
         1

SQL>
SQL> select utl_raw.cast_to_varchar2(b)
  2  from t
  3  where contains(b,'Hello') > 0;

UTL_RAW.CAST_TO_VARCHAR2(B)
---------------------------------------------------------------------------------
Hello there

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM