Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Help - PL/SQL and the LIKE clause

Re: Help - PL/SQL and the LIKE clause

From: DanHW <danhw_at_aol.com>
Date: 21 Nov 1998 03:14:41 GMT
Message-ID: <19981120221441.20750.00000854@ng-fb2.aol.com>


>Hi,
>
>If you code a select statement in PL/SQL where the LIKE clause uses a
>variable instead of a literal (example WHERE COL1 LIKE VAR_NAME vs.
WHERE
>COL1 LIKE 'VALUE%'), even though the value in the variable does not have a %
>in the front of the value, the optimizer does a full table scan instead of an
>index scan.
>
>
>Does anyone know a trick to tell the optimized to do an index scan short of
>using an INDEX hint?

Change your query to something like

WHERE COL1 > VALUE||' ' AND COL1 < VALUE||'~'

(if you want to be really picky use the ASC(0) and ASC(128) to add those characters instead what I think are the 1st and last printable characters) This will have the same effect as the LIKE because all values will fall between these, and I believe a bounded range uses the index.

Dan Hekimian-Williams Received on Fri Nov 20 1998 - 21:14:41 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US