我們在開發系統的時候經常會碰到類似如下這樣的情況:比如我有一張數據表
假如我現在要把紅圈中這列的的http://www.mylanqiu.com/ 這個字符串批量替換成mylanqiu 這個字符串,這個要怎么實現?其實這個很簡單,只要使用SQL的Replace函數就可以了,代碼如下:
update [HelloCode].[dbo].[AD] set [Contents]=REPLACE([Contents],'http://www.mylanqiu.com/','mylanqiu') where Contents like '%www.mylanqiu.com%'
Replace函數的用法:
Replace(數據庫的列名,'要被替換掉的字符串','要用於替換的字符串')