1. 程式人生 > 資料庫 >Mysql中批量替換某個欄位的部分資料(推薦)

Mysql中批量替換某個欄位的部分資料(推薦)

MYSQL中批量替換某個欄位的部分資料,具體介紹如下所示:

1.修改欄位裡的所有含有指定字串的文字

UPDATE 表A SET 欄位B = replace(欄位B,'aaa','bbb')
 example: update table set url= replace(url,'bbb') 【將url欄位中的aaa批量更改為bbb】
  update table set url= REPLACE (url,'3','1.png') where 條件; 

2.常規條件修改:

update table set column='' where column is null 
列:update `table` set `url`='0' where `url` is null 

知識點補充:mysql批量替換某個欄位的部分內容

舉例說明

有資料表person,結構如下

id name urls
1 張三 xh.jpg
2 李四 xh.jpg
3 王五 3.jpg

需求:將urls欄位中的xh替換為id欄位的值

語句:

UPDATE person SET urls = (REPLACE(urls,'xh',id));

執行結果:

id name urls
1 張三 1.jpg
2 李四 2.jpg
3 王五 3.jpg

總結

到此這篇關於Mysql中批量替換某個欄位的部分資料的文章就介紹到這了,更多相關mysql 批量替換欄位內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!