MySQL update替換字段部分內容

2022-03-22 18:17:38 字數 414 閱讀 7404

需求:資料庫info表中name欄位,值為beijingcar、beijingpeople、beijinghouse等;將該字段以beijing開頭更新成bj開頭。

解決:可以使用mysql內建的replace函式,具體用法如下:

update 表名 set 欄位名 = replace(object, 'search', 'replace');

update info set name = replace(name,'beijing','bj') where name like 'beijing%';

擴充套件:update `news` set `content`=replace(`content`,' ','');//清除news表中content欄位中的空格

mysql update正則替換sql語句

下面的update語句執行的是把www.test.中的test替換為abc 程式設計客棧程式 例句 update test set url replace www.test.com test abc where url regexp www.test.com 如果在記錄中,有類似 www.test....

MySQL update語句 批量更新某欄位

mysql 1 有時候要實現欄位的批量替換 update 表名 set 欄位a replace 欄位a png jpg 2 批量拼接字串到某欄位 update 表名 set 欄位a concat 欄位a update 表名 set 欄位a concat yyy 欄位a 3 批量擷取某欄位,扔掉開始的...

mysql update 在字段值結尾追加

更新乙個字段,在它的後面加乙個字串,不查詢資料庫得到這個字段值 例如 我的test表,有個user欄位,我現在想在它後面加了另乙個使用者的名字 phpchina mysql資料庫這樣寫 update test set user user phpchina where id 2 這樣是不對的,mysq...