Link to home
Start Free TrialLog in
Avatar of Swaminathan K
Swaminathan KFlag for India

asked on

need help on sql

Hi ,

I need to know the difference between using like operator or DBMS_LOB.INSTR for an CLOB column. I need to know which one is better and efficient in processing

Select *
from user_notes where lower(description) like '%abd%'

or
Select *
From user_notes where DBMS_LOB.INSTR(lower(description),'abc') >0;

Here description is an CLOB column
SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sean Stuber
Sean Stuber

neither one is good, but the LIKE should be more efficient because you won't be incurring sql - pl/sql context switches

but definitely test it for yourself
note, if you have a specific substring that you will always be searching for, then you could create a function-based index that would be very efficient

CREATE INDEX idx_user_notes_abc ON user_notes (DBMS_LOB.INSTR(lower(description),'abc'));


but, this does not work if you will be searching for variable strings because you would need to create a separate index for every possible string.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Couldn't a context index be in order here? I've had some pretty good experience with them although I've never combined them with a function like lower() on the indexed column.
awking00,

Yes, Oracle Text is the correct way to go and it is case insensitive so no need for lower.

Check out the askers previous questions, for some reason they have been asked to NOT use a Text index:
https://www.experts-exchange.com/questions/28528077/need-help-on-oracle-indexes.html
slightwv,
That's an odd restriction. As you and sdstuber both indicated, "You can use this paint brush to drive that nail, but not this hammer."
When I see people doing searches like this I suggest this exercise to try to relate to the problem.

Grab a dictionary, find all words that begin with "p".
Within a few seconds they have pinched off the pages with those words.
The alphabet makes a great index.  If your dictionary has labeled thumb tabs it's even easier.  Regardless, it's a trivial effort.

Now,  find all words that have a "p" in the middle.
When they inevitably responde: "I can't do that - I'd have to read the entire dictionary"

Then they have the answer as to why these searches don't work.
Avatar of Swaminathan K

ASKER

thanks a lot.