MySql - Way to update portion of a string?

后端 未结 4 1236
粉色の甜心
粉色の甜心 2020-11-29 20:52

I\'m looking for a way to update just a portion of a string via MySQL query.

For example, if I have 10 records all containing \'string\' as part of the field value

相关标签:
4条回答
  • 2020-11-29 21:20

    Does something like this work in any way?

    update table_name
    set column_name = replace(column_name, 'string%', 'string') 
    where column_name like '%string%'
    
    0 讨论(0)
  • 2020-11-29 21:25

    Use the LIKE operator to find the rows that you care about and update them using the REPLACE function.

    For example:

    UPDATE table_name SET field_name = REPLACE(field_name,'search','replace') WHERE field_name LIKE '%some_value%'
    
    0 讨论(0)
  • 2020-11-29 21:30
    UPDATE `table` SET `field` = REPLACE(`field`, 'string', 'anothervalue')
    
    0 讨论(0)
  • 2020-11-29 21:34

    I think this should work:

    UPDATE table
    SET field = REPLACE(field, 'string', 'anothervalue')
    WHERE field LIKE '%string%';
    
    0 讨论(0)
提交回复
热议问题