天天看點

mysql資料庫的replace方法更新字段值

1. 将字元串1與字元串2之間的内容替換成指定字元串

UPDATE  t_content_info  SET  content= REPLACE( content,SUBSTRING(content,LOCATE('字元串1', content),locate('字元串2', content)-locate('字元串1'+20, content)), '替換字元串' );

2. 如果字段以指定字元串結尾,則删除該字元串或替換成其他字元串

UPDATE t_content_info  SET  content= REPLACE(content,'結尾字元串', '替換字元串' ) WHERE RIGHT(`content`,1) = '結尾字元串';

3. 删除指定字元及其後面的所有字元

UPDATE t_content_info  SET content=SUBSTR(content,1,LOCATE('指定字元串',content)-1) WHERE contentLIKE '%指定字元串%' ;