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.)

Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment.

-Siddhārtha Gautama (The Buddha)