簡體   English   中英

MySql - 更新字符串部分的方法?

[英]MySql - Way to update portion of a string?

我正在尋找一種方法來通過 MySQL 查詢更新字符串的一部分。

例如,如果我有 10 條記錄都包含“字符串”作為字段值的一部分(即,“某事/字符串”、“某事/字符串看這里”、“某事/字符串/等等”,有沒有辦法更改“字符串” ' 通過一個查詢將每一行的 'anothervalue' 轉換為 'something/anothervalue'、'something/anothervaluelookhere'、'something/string/etcetera',有沒有辦法改變 'anothervalue'

我認為這應該有效:

UPDATE table
SET field = REPLACE(field, 'string', 'anothervalue')
WHERE field LIKE '%string%';
UPDATE `table` SET `field` = REPLACE(`field`, 'string', 'anothervalue')

使用LIKE運算符查找您關心的行並使用REPLACE函數更新它們。

例如:

UPDATE table_name SET field_name = REPLACE(field_name,'search','replace') WHERE field_name LIKE '%some_value%'

像這樣的事情有什么作用嗎?

update table_name
set column_name = replace(column_name, 'string%', 'string') 
where column_name like '%string%'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM