NYCPHP Meetup

NYPHP.org

[nycphp-talk] Escaping special character like *, + in sql where clause

Daniel Convissor danielc at analysisandsolutions.com
Fri Oct 8 18:19:24 EDT 2004


On Fri, Oct 08, 2004 at 01:24:03PM -0700, Sumithra S.Nair wrote:
>    How can I escape these characters in the sql where clause. 
>  
> Select * from table1 where name like 'John smith*'.
> The * is part of the name itself.

% and _ are wildcard characters in LIKE predicates, not *.

Now, the trick is how to escape THOSE. :)  Here's what the SQL-99 
standard says:

    select * from foo where cf like 'a^%%' escape '^'

You can pick any character you want for the escape.

It works for most DBMS's, though don't try it with SQLite.

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list