最近在研究cms,在數據轉換的時候需要用到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,
‘../../../../../../’,
‘http://special.dayoo.com/meal/’ );?
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.163.com‘,‘w‘,‘ww‘)—>www www.163.com
例:把表table中的name字段中的 aa替換為bbupdate table set name=replace(name,‘aa‘,‘bb‘)?
?以上就是使用mysql的replace函數替換字符串的內容,更多相關文章請關注PHP中文網(www.php.cn)!