Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle blob text search

Is it possible to search through blob text using sql statement? I can do select * from $table where f1 like '%foo%' if the f1 is varchar, how about f1 is a blob? Any counter part for this?

like image 948
Skay Avatar asked Jun 03 '10 06:06

Skay


People also ask

How do I search for a specific word in Oracle?

To enter an Oracle Text query, use the SQL SELECT statement. Depending on the type of index, you use either the CONTAINS or CATSEARCH operator in the WHERE clause. You can use these operators programatically wherever you can use the SELECT statement, such as in PL/SQL cursors.

What is Dbms_lob Instr?

INSTR Function. This function returns the matching position of the nth occurrence of the pattern in the LOB , starting from the offset you specify.

What is Dbms_lob Substr?

When calling DBMS_LOB . SUBSTR from the client (for example, in a BEGIN / END block from within SQL*Plus), the returned buffer contains data in the client's character set. Oracle converts the LOB value from the server's character set to the client's character set before it returns the buffer to the user.


2 Answers

This is quite possible and easy to do.

Simply use dbms_lob.instr in conjunction with utl_raw.cast_to_raw

So in your case, if t1 is a BLOB the select would look like:

select *   from table1  where dbms_lob.instr (t1, -- the blob                    utl_raw.cast_to_raw ('foo'), -- the search string cast to raw                    1, -- where to start. i.e. offset                    1 -- Which occurrance i.e. 1=first                     ) > 0 -- location of occurrence. Here I don't care.  Just find any ; 
like image 156
Olafur Tryggvason Avatar answered Oct 02 '22 11:10

Olafur Tryggvason


If it is a Word or PDF document, look into Oracle Text.

like image 30
Gary Myers Avatar answered Oct 02 '22 10:10

Gary Myers