Home > Database > Mysql Tutorial > body text

mysql中like和replace批量查找和批量替换

WBOY
Release: 2016-06-07 17:51:42
Original
1644 people have browsed it

文章介绍了最简单的like和replace来实现批量查找和批量替换的方法,有需要了解的朋友可以参考一下。

批量查找

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

 代码如下 复制代码
SELECT a.products_name FROM nike.products_description a WHERE a.products_name like '%#%'

#为要查找的字符串

 replace批量替换:

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

语法
REPLACE ( ’string_expression1′ , ’string_expression2′ , ’string_expression3′ )

参数
’string_expression1′

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

’string_expression2′

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

’string_expression3′

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

返回类型
假如 string_expression(1、2 或 3)是支持的字符数据类型之一,则返回字符数据。假如 string_expression(1、2 或 3)是支持的 binary 数据类型之一,则返回二进制数据。

 代码如下 复制代码

UPDATE article SET
content = replace(content, ’sjolzy’, ’sjolzy.cn')
WHERE name like '%#%';

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!