首页 > 文章列表 > 如何使用批量搜索替换功能在MySQL数据库中修改内容?

如何使用批量搜索替换功能在MySQL数据库中修改内容?

mysql 数据库
230 2023-05-02

批量搜索替换MySQL数据库中的内容

语句如下:

 UPDATE table SET field = replace(field, text_needs_to_be_replaced, text_required);

例如,如果我想用下面的Mark替换所有的John,

UPDATE student SET student_name = replace(student_name, 'John', 'Mark');

语句如下 发放

以上替换是对所有的student_name 进行搜索替换,如果需要限定特定的数据,后面可以加where限定,如下:

UPDATE student SET student_name = replace(student_name, 'John', 'Mark') where id =11;