Oracle SQL query not like %

Toronto, 2013.06.10

I learned something from one of our more clever developers today. If you want to do an SQL query of an Oracle database that excludes the '%' character, it's tricky. Whereas the following works on MySQL:

select * from equities where name not like '%%%'

It doesn't work on an Oracle system because % means "match everything" and you haven't properly escaped the middle '%' character in the query. You need:

select * from equities where name not like '%%%' escape ''

leave a comment

By submitting this form you agree to the privacy terms.
 

rand()m quote

(In which I leave the final word to someone else.)

Being a real writer means being able to do the work on a bad day.

-Norman Mailer