skip to Main Content

I want to update a table with a new url to replace the old one:

UPDATE table1 
SET column1 = REPLACE(column1, 'OLD URL', 'NEWURL') 
WHERE column LIKE '%OLDURL%'

This updates it mostly but I only want to replace part of it, and if I put any / in it doesn’t work, so if I want to use:

UPDATE table1 
SET column1 = REPLACE(column1, 'OLD URL/folder1', 'NEWURL') 
WHERE column LIKE '%OLDURL%'

It doesn’t work because of the the /.

2

Answers


  1. The quickest fix to your second update query is to just include the path component in the replacement:

    UPDATE table1 
    SET column1 = REPLACE(column1, 'OLD URL/folder1', 'NEWURL/folder1') 
    WHERE column LIKE '%OLDURL%';
    
    Login or Signup to reply.
  2. You should check for the replacement pattern in the where:

    UPDATE table1 
        SET column1 = REPLACE(column1, 'OLD URL/folder1', 'NEWURL') 
        WHERE column LIKE '%OLDURL/folder1%';
    

    I’m not sure if that addresses what you mean by “doesn’t work”, though.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search