2019年8月22日 星期四

mysql string 處理



取代字串:REPLACE(`欄位名稱`, '欲取代的字串', '取代後的字串')


UPDATE `table` SET `column` = REPLACE(`column`, 'efg', 'xxx') WHERE `column` LIKE 'efg%';



連接字串:CONCAT('字串1', '字串2', ... '字串n')


 UPDATE `table` SET `column` = CONCAT('123', `column`) WHERE `column`='45'; 
(Result: 12345) 



UPDATE `table` SET `column` = CONCAT(`column`, '123') WHERE `column`='456'; 
(Result: 456123) 


 UPDATE `table` SET `column` = CONCAT('123', `column`, '789') WHERE `column`='456'; 
(Result: 123456789)