CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(t_content1,'"bigImgUrl":',-1),'/',6),'/98x98_',SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(t_content1,'"bigImgUrl":',-1),'"',2),'/',-1),'"') as "new smallUrl"
REPLACE(t_content1,CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(t_content1,'"smallUrl":',-1),'"',2),'"'),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(t_content1,'"bigImgUrl":',-1),'/',6),'/98x98_',SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(t_content1,'"bigImgUrl":',-1),'"',2),'/',-1),'"')) as new_t_content1
FROM test_book_class WHERE ccdl_type=5
AND t_content1 LIKE '%"bigImgUrl":"http://abc.test.com%'
AND t_content1 LIKE '%"smallUrl":"http://dl.test.com/%'
LIMIT 10;
比较修改前的内容和修改后的内容,确定被修改的部分是正确的。
执行SQL
注意:先测试库,后生产库。
UPDATE test_book_class SET t_content1=REPLACE(t_content1,CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(t_content1,'"smallUrl":',-1),'"',2),'"'),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(t_content1,'"bigImgUrl":',-1),'/',6),'/98x98_',SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(t_content1,'"bigImgUrl":',-1),'"',2),'/',-1),'"'))
WHERE ccdl_type=5 AND t_content1 LIKE '%"bigImgUrl":"http://abc.test.com%' AND t_content1 LIKE '%"smallUrl":"http://dl.test.com/%';