數據庫修改某個字段的部分或所有內容

1*.需求html

將表(Ws_FormMain)的字段(order_Number)內容爲XSRK201706080001修改成WXSK201706080001sql

update 表名 set 字段 = replace(字段, '要修改的內容' , '修改後的內容');數據庫

UPDATE Ws_FormMain SET order_Number = REPLACE(order_Number, 'XSRK', 'WXSK') WHERE orderDefId = 513函數

 

2*.須要修改sqlserver數據庫中某一字段的值,例如從「1234560001」至「1234560999」的字段supplier_id進行修改,要求修改後的supplier_id字段值爲「654321****」。sqlserver

能夠使用replace()函數進行修改:update  table  set  supplier_id=replace(supplier_id,'123456','654321') where supplier_id like '123456%';url

replace()函數中,第一個參數表示的是須要進行操做的字段或值,第二個參數表示的須要被替換的字符串,第三個參數表示進行替換的字符串.net

 

MYSQL中批量替換某個字段的部分數據:orm

1.修改字段裏的全部含有指定字符串的文字
UPDATE 表A SET 字段B = replace(字段B, 'aaa', 'bbb')
    example: update  table set url= replace(url, 'aaa', '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

 

 

 

參考網址:https://blog.csdn.net/jiangnanqbey/article/details/81304834server

       https://www.cnblogs.com/hao-1234-1234/p/10717864.htmlhtm

       https://blog.csdn.net/qq_14997169/article/details/53241395

     https://blog.csdn.net/john320/article/details/16887967

相關文章
相關標籤/搜索