如何在mysql列中查找和替换单词? [英] how to find and replace a word in a mysql column?

查看:233
本文介绍了如何在mysql列中查找和替换单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列包含街道列表的列.我需要将街道"替换为圣".可以使用所需格式的地址在当前列或新列中进行替换.以下是示例数据. 列1"包含当前格式的数据. 第2列"包含所需格式的数据.

I have a column containing list of streets. I need to replace 'street' with 'St'. The replacement can be made in the current column or in a new column with the address in the required format. The following is the sample data. 'Column 1' contains the data in current format. 'Column 2' contains the data in the desired format.

Column 1         Column 2
Hillary Street   Hillary St
Golf Road        Golf Road
Oldwood Street   Oldwood St

我该怎么做?

此查询适用于此:

UPDATE table SET column = REPLACE(column, 'Street', 'St');

是否可以为此列设置规则.这样添加到此的所有数据会自动以这种方式格式化吗?还是我每次都需要重复此查询?

Is it possible to set a rule to this column. Such that all data added to this get formatted this way automatically? Or I need to repeat this query each time?

推荐答案

运行这样的查询以在相同列中进行更新:

Run a query like this to update in the same column:

UPDATE table 
   SET column = REPLACE(column, 'Street', 'St');

这篇关于如何在mysql列中查找和替换单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆