SQL的四种匹配模式

原文链接:https://blog.csdn.net/qq_36113598/article/details/79372493

SQL提供了四种匹配模式:% _ [ ] [^ ]

1. %
%表示模糊匹配0或多个字符,如以下查询语句:
select * from user where name like '%三%'; 这个语句将会把name中带有“三”的信息全部查找出来
select * from user where name like '%三' ; 这个语句将会把name中最右边带有“三”的信息全部查找出来
select * from user where name like '三%' ; 这个语句将会把name中最左边带有“三”的信息全部查找出来

2. _
_表示任意单个字符,如以下语句:
select * from user where name like '_三_'; 这个语句会匹配出“二三四”
select * from user where name like '__三'; 这个语句会匹配出“一二三”

3. [ ]
[ ]表示括号内所列字符中的一个(类似于正则表达式),如以下语句:
select * from user where name like '老[大二三]'; 如果都存在的话将找出“老大”、“老二”、“老三”
同时支持缩写0-9、a-z等。

4.[^ ]
类似于正则表达式,将括号内的元素排除,如以下语句:
select * from user where name like '[0-3]个' 将会检索出除了“0个”,“1个”,“2个”,“3个”
---------------------
作者:MuffinFish
来源:CSDN
原文:https://blog.csdn.net/qq_36113598/article/details/79372493
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-03-15 17:36  snoweveryday  阅读(597)  评论(0编辑  收藏  举报