Home  >  Article  >  Database  >  mysql字符串批量查找和替换

mysql字符串批量查找和替换

WBOY
WBOYOriginal
2016-06-07 17:52:331629browse

在mysql中批量查询我们使用了like通配符,替换我们直接使用replace 与update联合使用,下面我来举实例说明。

通配符 说明
_    与任意单字符匹配
 
%    与包含一个或多个字符的字符串匹配
 
[ ]  与特定范围(例如,[a-f])或特定集(例如,[abcdef])中的任意单字符匹配。
 
[^]  与特定范围(例如,[^a-f])或特定集(例如,[^abcdef])之外的任意单字符匹配

批量查找:

 代码如下 复制代码

SELECT a.products_name FROM nike.products_description a WHERE a.products_name like '%#%'

#为要查找的字符串

批量替换:

REPLACE
用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式。

语法
REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )

参数
'string_expression1'

待搜索的字符串表达式。string_expression1 可以是字符数据或二进制数据。

'string_expression2'

待查找的字符串表达式。string_expression2 可以是字符数据或二进制数据。

'string_expression3'

替换用的字符串表达式。string_expression3 可以是字符数据或二进制数据。

 

 代码如下 复制代码
UPDATE article SET content = replace(content, ’sjolzy’, ’sjolzy.cn') WHERE name like '%#%';

article为表 content为字段  sjolzy为要被替换的  sjolzy.cn为替换的值

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn