【问题标题】:How to text search in BLOB field如何在 BLOB 字段中进行文本搜索
【发布时间】:2020-05-23 11:18:01
【问题描述】:

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

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

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

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 

【问题讨论】:

标签: sql oracle


【解决方案1】:

您可以在 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

【讨论】:

    猜你喜欢
    • 2017-09-06
    • 2017-05-20
    • 2012-01-13
    • 2014-09-16
    • 2021-01-24
    • 2020-10-29
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    相关资源
    最近更新 更多