Re: SQL 'Like' operator

From: Michael Krolewski <mkrolews_at_upw.com>
Date: 1996/07/30
Message-ID: <31FE2FEC.1072_at_upw.com>#1/1


Atul Batra wrote:
>
> Hi all --
>
> Is it possible to use the LIKE operator using a host variable in
> PRO*C ?? I need to search VARCHAR fields with just the first few letters.
> Something like -
>
> SELECT ename
> FROM emp_table
> WHERE ename LIKE :host_variable ;
> /* 'host_variable' contains the string 'stev' and it should pull out
> 'steven'
> */
>
> Thanks in advance,
>
> Atul Batra
> abatra_at_unix1.sncc.lsu.edu

There are two approachs.

First is to use the above statement and make sure that the :host_variable is <single quote><search string><wild card><single quote> eg 'stev%'

That should work. Obviously you need to add the extra characters. Similarly, you could add them to the EXEC SQL eg WHERE ename LIKE ':host_variable%';

Alternatively, you can use the EXEC SQL PREPARE to construct the cursor. This is probably overkill in this case but is very useful for IN ( <clause> ) statements. The Oracle system does not allow passing "'stev','fred','barney'" and interupting them correctly. Similarly, this is good if you want to allow for variable changes to the select or variable number of arguements in the cursor.

Mike Krolewski Received on Tue Jul 30 1996 - 00:00:00 CEST

Original text of this message