优秀的编程知识分享平台

网站首页 > 技术文章 正文

SQL|模糊匹配regexp_like和like函数的实战练习

nanyue 2024-07-25 05:52:23 技术文章 20 ℃

本期主要介绍SQL中的单条件模糊匹配函数like和多条件模糊匹配函数regexp_like的使用,详细介绍如下:


1??单条件模糊匹配函数like

  • 例如有一个表 table_name

id name

1 a

2 abc

3 bc

4 NULL

5 ccb

============

如果利用如下语句查询

select *

from table_name

where name not like '%a%'

会忽略null,查不出来第4行记录 (三值逻辑unknown)

2??多条件模糊匹配regexp_like

示例如下

where talbe.name not like '%测试%'

and talbe.name not like '%test%'

可转换为>>>

where not regexp_like(talbe.name,'(测试|test)')

业务应用>>>

regexp_like(a.fifth_category_name,'要求开发票|发票问题')


另外还有两个衍生出来的模糊匹配函数,如下~

1.右模糊匹配函数?:

语法?:regexp_like(col, '^(str1|str2|...)')

2.左模糊匹配函数?:

语法?:regexp_like(col, '(str1|str2|...)#39;)

Tags:

最近发表
标签列表