简体   繁体   English

MySQL替换列中的字符

[英]MySQL Replace character from column

I would like to replace all occurences of 's with s in myTable's name column. 我想,以取代所有出现'ss在myTable的名字列。 I tried REPLACE but it replaces all records. 我尝试过REPLACE但它取代了所有记录。 I want to do it for some customers. 我想为一些客户做。

Note: Customer is foreign key in myTable. 注意:客户是myTable中的外键。

Thanks in advance 提前致谢

Update: 更新:

I tried some queries REPLACE(name, "'s", "s") from data where cust_id = 1 but this doesn't work 我尝试REPLACE(name, "'s", "s") from data where cust_id = 1查询一些查询REPLACE(name, "'s", "s") from data where cust_id = 1但这不起作用

From one of questions I tried SELECT REPLACE(name, "'s", "s") from data where cust_id = 1 . 从一个问题中,我尝试SELECT REPLACE(name, "'s", "s") from data where cust_id = 1 This is replacing all records in table 这将替换表中的所有记录

A simple replace across all records in the table can be done with: 可以使用以下方法对表中的所有记录进行简单替换:

 UPDATE myTable
 set    name = REPLACE(name, '\'s', 's')

If you want to filter the records to be updated from another table, then you can do something like 如果要过滤要从另一个表更新的记录,则可以执行以下操作

 UPDATE myTable
 LEFT JOIN CustomerTable ON myTable.Customer = CustomerTable.Customer
 SET    name = REPLACE(name, '\'s', 's')
 WHERE  CustomerTable.Field > SomeCondition <== Replace with what you need.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM