如何在字段中查找字符串并在mysql数据库中添加url?
我想知道如何在表字段中查找字符串的所有可能实例,例如如何在字段中查找字符串并在mysql数据库中添加url?,mysql,Mysql,我想知道如何在表字段中查找字符串的所有可能实例,例如 uploads/ http://example.com/ 并在所有字符串之前添加另一个字符串,例如 uploads/ http://example.com/ 我的想法是更新数据库中旧链接不起作用的所有记录,因此对于Instance,我有类似于perex的字段 Check this car <img src="/uploads/audi.jpg">. It is fantastic! 检查这辆车。太棒了! 看起来像: C
uploads/
http://example.com/
并在所有字符串之前添加另一个字符串,例如
uploads/
http://example.com/
我的想法是更新数据库中旧链接不起作用的所有记录,因此对于Instance,我有类似于perex的字段
Check this car <img src="/uploads/audi.jpg">. It is fantastic!
检查这辆车。太棒了!
看起来像:
Check this car <img src="http://example.com/uploads/audi.jpg">. It is fantastic!
检查这辆车。太棒了!
我的数据库中有数百种这种情况
更新查询会是什么样子?假设我们在一个名为cars的表中有它,字段名为perex。我们需要找到所有/uploads的实例,并在斜杠前添加http://example.com/
提前谢谢你的回答
UPDATE cars
SET perex = REPLACE(perex, '/uploads/', 'http://example.com/uploads/')
WHERE INSTR(perex, '/uploads/');
见:
Update table
set Perex = Replace (Perex, 'Check this car <img src="', 'Check this car <img src="http://example.com')
Where Perex like '%uploads/%'
更新表
设置Perex=更换(Perex,'检查这辆车