[英]How to text search in BLOB field
We have created a BLOB type column to store 6000 to 7000 ASCII characters of payload.我们创建了一个 BLOB 类型列来存储 6000 到 7000 个 ASCII 字符的有效负载。 I am inserting the payload using following code.
我正在使用以下代码插入有效负载。
PreparedStatement stmt=conn.prepareStatement(insertQuery);
String record="My ASCII Payload";
stmt.setBytes(1, record.getBytes());
stmt.execute();
When i run below query i can see the length of chars in the output.当我在查询下运行时,我可以看到 output 中的字符长度。
select dbms_lob.getLength(MY_PAYLOAD)
from RAW_DATA;
6085
I wanted to perform text search in this BLOB column, i tried following options nothing works.我想在这个 BLOB 列中执行文本搜索,我尝试了以下选项,但没有任何效果。 What is the correct way to perform text search in a BLOB column?
在 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
You can create text indexes on blobs as long as they contain text (naturally)您可以在 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.