Connecting Tech Pros Worldwide Help | Site Map

SELECT ... WHERE column LIKE parameter||'%'

  #1  
Old June 27th, 2008, 08:04 PM
Heini =?ISO-8859-2?B?Tm9sc/hl?=
Guest
 
Posts: n/a
I have a database containing alot of procedures with this kind of coding logic:


BigTable
column1 varchar2(40);


Procedure SomeProcedure (in_parameter varchar2)
SELECT column1
FROM BigTable
WHERE column1 LIKE in_parameter||'%';
END;


The procedure is called like this:

SomeProcedure('abc');


Although this coding logic selects the correct rows, there is a big problem - it does not use the index on BigTable.
But if you do perform at little test and change the procedure like this:


Procedure SomeProcedure (in_parameter varchar2)
SELECT column1
FROM BigTable
WHERE column1 LIKE 'abc'||'%';
END;

Then it uses the index. But ofcourse now there is not the desired flexibility of using a parameter.


QUESTIONS:
1. Why does Oracle not use the index when a parameter is used in the LIKE-statement?

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
SELECT ... WHERE column LIKE parameter||'%' Heini Nolsøe answers 0 August 11th, 2006 10:35 AM
Speeding up LIKE with placeholders? Dan Sugalski answers 11 November 23rd, 2005 02:05 AM
passing parameter js answers 4 July 23rd, 2005 10:19 AM
Encryption and "WHERE encrypted_column LIKE" joshsackett answers 10 July 23rd, 2005 10:17 AM