Skip to content
Advertisement

How to escape slashes in LIKE clause

I need to do some clean-up in a database and change some urls from http://www.domain1.com to http://www.domain2.com, so I am doing a query like this:

UPDATE mytable set url = REPLACE(url, '"http://www.domain1.com"', '"http://www.domain2.com"')

the double comma is needed as this strings are part of a JSON string

however, the problem is that in the DB the old url is for some reason escaped so I have something like this

http://www.domain1.com

if I run a query like these they don’t match anything

select * from mytable where url like '%http://www.domain1.com%'
select * from mytable where url like '%http://www.domain1.com%'

and therefore the replace query doesn’t work either, so what’s the correct way to escape these strings?

Advertisement

Answer

You might try:

where url like '%http:\/\/www.domain1.com%'

To be honest, I don’t understand how or why forward slashes would be escaped. Perhaps you are better off just using a wildcard:

where url like '%http:_/_/www.domain1.com%'
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement