mySQL中replace的用法

2021-06-23 06:19:36 字數 2277 閱讀 5993

mysql replace例項說明:

update tb1 set f1=replace(f1, 'abc', 'def'); 

replace(str,from_str,to_str) 

在字串 str 中所有出現的字串 from_str 均被 to_str替換,然後返回這個字串 

這個函式用來批量替換資料中的非法關鍵字是很有用的!如下例子: 

例1:update bbstopic set tcontents = replace(replace(tcontents,'abcde','') ,'****','') where tcontents like '%abcde%' or tcontents like '%****%' 

例2:update typetable set type_description=replace(type_description,'360',''); 

mysql replace用法 

1.replace into

replace into table (id,name) values('1','aa'),('2','bb') 

此語句的作用是向表table中插入兩條記錄。如果主鍵id為1或2不存在 

就相當於 

insert into table (id,name) values('1','aa'),('2','bb') 

如果存在相同的值則不會插入資料 

2.replace(object,search,replace)

把object中出現search的全部替換為replace 

select replace('www.jb51.net','w','ww')--->wwwwww.jb51.net 

例:把錶table中的name欄位中的aa替換為bb 

update table set name=replace(name,'aa','bb') 

mysql replace函式我們經常用到,下面就為您詳細介紹mysql replace函式的用法,希望對您學習mysql replace函式方面能有所啟迪。 

最近在研究cms,在資料轉換的時候需要用到mysql的mysql replace函式,這裡簡單介紹一下。 

比如你要將表 tb1裡面的 f1欄位的abc替換為def 

update tb1 set f1=replace(f1, 'abc', 'def'); 

replace(str,from_str,to_str) 

在字串 str 中所有出現的字串 from_str 均被 to_str替換,然後返回這個字串: 

mysql> select replace('www.mysql.com', 'w', 'ww'); 

-> 'wwwwww.mysql.com' 

這個函式是多位元組安全的。 

示例: 

update `dede_addonarticle` set body = replace ( body, 

'', 

'' ); 

update `dede_addonarticle` set body = replace ( body, 

'', 

'' ); 

update `dede_addonarticle` set body = replace ( body, 

'', 

'' ); 

update `dede_archives` set title= replace ( title, 

'大洋新聞 - ', 

'' ); 

update `dede_addonarticle` set body = replace ( body, 

'../../../../../../', 

'' ); 

mysql replace

用法1.replace intoreplace into table (id,name) values(『1『,『aa『),(『2『,『bb『) 

此語句的作用是向表table中插入兩條記錄。 

2.replace(object, search,replace) 

把object中出現search的全部替換為replaceselect replace(『www.jb51.net『,『w『,『ww『)--->www www.jb51.net 

例:把錶table中的name欄位中的 aa替換為bbupdate table set name=replace(name,『aa『,『bb『)

mySQL中replace的用法

mysql replace函式我們經常用到,下面就為您詳細介紹mysql replace函式的用法,希望對您學習mysql replace函式方面能有所啟迪 mysql replace例項說明 update tb1 set f1 replace f1,abc def replace str,from...

mySQL中replace的用法

mysql replace函式我們經常用到,下面就為您詳細介紹mysql replace函式的用法,希望對您學習mysql replace函式方面能有所啟迪update tb1 set f1 replace f1,abc def replace str,from str,to str 在字串 str...

mySQL中replace的用法

mysql有什麼辦法批量去掉某個字段字元中的空格?不僅是字串前後的空格,還包含字串中間的空格,答案是 replace,使用mysql自帶的 replace 函式,另外還有個 trim 函式。1 mysql replace 函式 語法 replace object,search,replace 意思 ...