Home » SQL & PL/SQL » SQL & PL/SQL » instr vs DBMS_LOB.instr (11g, Linux)
instr vs DBMS_LOB.instr [message #546930] |
Sat, 10 March 2012 05:49  |
 |
bigdataboy
Messages: 3 Registered: March 2012
|
Junior Member |
|
|
Hi everyone.
Straight to the point: I need to search a pattern backwards in a CLOB field.
Function DBMS_LOB.instr does not work with '-1' offset (where to start the search) as instr does.
Parameters: instr(text_to_be_searched, pattern, offset, nth)
Example: I want to search 'Hello world' for the first instance of the letter 'o' starting from the end, backwards.
As you can see, result for DBMS_LOB.instr is null when entered -1 for offset.
select
DBMS_LOB.instr('Hello world','o',-1,1) lob_i,
instr('Hello world','o',-1,1) std_i
from dual;
How can I work it out?
Thanks a lot.
|
|
|
|
Re: instr vs DBMS_LOB.instr [message #546967 is a reply to message #546934] |
Sat, 10 March 2012 15:49   |
 |
Barbara Boehmer
Messages: 9105 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
Although in current versions you can use INSTR on LOBs, you usually get better performance from DBMS_LOB.INSTR on LOBs. You can use REVERSE and DBMS_LOB.GETLENGTH to enable you to use DBMS_LOB.INSTR as shown below, but I suspect that may reduce performance enough that you are better off with just INSTR.
SCOTT@orcl_11gR2> select
2 DBMS_LOB.instr ('Hello world', 'o', -1, 1) lob_i,
3 instr ('Hello world', 'o', -1, 1) std_i,
4 dbms_lob.getlength ('Hello world')
5 - dbms_lob.instr (reverse ('Hello world'), 'o', 1, 1)
6 + 1 rev_lob_i
7 from dual;
LOB_I STD_I REV_LOB_I
---------- ---------- ----------
8 8
1 row selected.
|
|
|
|
|
Re: instr vs DBMS_LOB.instr [message #546995 is a reply to message #546992] |
Sun, 11 March 2012 01:21   |
 |
Michel Cadot
Messages: 68758 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote:it seems instr has same behaviour with backward direction as dbms_lob.instr
Are you sure?
SQL> l
1 declare c clob; i integer;
2 begin
3 dbms_lob.CREATETEMPORARY (c, TRUE);
4 c := rpad (' ', 4000) || rpad (' ', 4000) || rpad (' ', 4000) || 'Hello world';
5 i := INSTR (c, 'o',-1,1) ;
6 dbms_output.put_line(i);
7* end;
SQL> /
12008
Regards
Michel
|
|
|
|
Goto Forum:
Current Time: Sat May 31 06:20:47 CDT 2025
|