| Sqlserver中Replace函數(shù):實(shí)現(xiàn)字段中某個(gè)字符串批量替換。 注意:強(qiáng)烈建議替換前備份數(shù)據(jù)庫以免發(fā)生災(zāi)難性后果。 update article set [Content]=replace([content],'www.abc.com','www.bbb.com'); 說明:將content字段中的 www.abc.com 替換===> www.bbb.com 如果content字段類型為text,會(huì)報(bào)錯(cuò):參數(shù)數(shù)據(jù)類型 text 對(duì)于 replace 函數(shù)的參數(shù) 1 無效。 對(duì)text或ntext類型的數(shù)據(jù)在查詢中不能進(jìn)行字符串操作。這時(shí)用得最多的是把text當(dāng)作varchar(實(shí)際內(nèi)容長度低于8000字節(jié)時(shí))或把ntext當(dāng)作nvarchar(實(shí)際內(nèi)容長度低于4000字節(jié)時(shí))來處理 update article set [Content]=Replace(Cast([Content] as nvarchar(4000)),'oldkeyword','newkeyword'); update article set [Content]=Replace(Cast([Content] as varchar(8000)),'oldkeyword','newkeyword’); 
 特別提醒: 在使用replace函數(shù)時(shí),第一個(gè)參數(shù)一定不要加引號(hào): 比如: update focusimg set src=replace('src','www.abc.com','www.bbb.com'); 他會(huì)將src字段全部替換為src字符串,這就是災(zāi)難性后果,所以前面提醒要備份。 | 
|  |