I would like to know how to find in a table field all possible instances of a string e.g.
uploads/
and add before all of them another string e.g.
http://example.com/
My idea is to update all my records in database where the old links are not working so for instace I have something like this for a field perex
Check this car <img s开发者_如何学Pythonrc="/uploads/audi.jpg">. It is fantastic!
To look like:
Check this car <img src="http://example.com/uploads/audi.jpg">. It is fantastic!
And I have hundreds of this situations in my db.
What could an update query look like? Assume we have it in one table called cars and field is called perex. We need to find there all instances of /uploads and add before the slash http://example.com/
Thanks in advance for your answer.
UPDATE cars
SET perex = REPLACE(perex, '/uploads/', 'http://example.com/uploads/')
WHERE INSTR(perex, '/uploads/');
See:
REPLACE()
INSTR()
Try this
Update table
set Perex = Replace (Perex, 'Check this car <img src="', 'Check this car <img src="http://example.com')
Where Perex like '%uploads/%'
精彩评论