简体   繁体   English

如何在MySQL中将子字符串替换为列值?

[英]How to replace a substring to a column value in MySQL?

I have a big database in which the website column values are malformed: 我有一个很大的数据库,其中的website列值格式错误:

http://.www.123.com.au, http://.www.exampleurl.com

I want to correct these urls by removing this extra character . 我想通过删除此多余的字符来更正这些网址. as: 如:

http://www.123.com.au, http://www.exampleurl.com

I get these values by passing following select statement: 我通过传递以下选择语句来获得这些值:

SELECT * 
FROM  `tbl_business` 
WHERE  `website` LIKE  'http://.%';
UPDATE your_table
SET your_field = REPLACE(your_field, 'http://.www', ' http://www')
WHERE your_field LIKE '%http://.ww%';

The REPLACE function is the simplest way I know to do this and once you know it is there it is a very useful tool. REPLACE函数是我知道的最简单的方法,一旦知道它就可以使用,它是一个非常有用的工具。 In this case I guess you would not need the WHERE clause if it is a small number of records, but I would add it so you work on only subset of the data, better for larger data sets and to avoid unintended consequences. 在这种情况下,我猜想如果它是少量记录,则不需要WHERE子句,但是我会添加它,以便您仅处理数据的子集,更好地用于较大的数据集并避免意外的后果。

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

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