解释:

确定给定的字符串和指定的模式是否相同.

语法:

match_expression [not] like pattern [ESCAPE escape_character]

参数:

match_expression:任何字符串数据类型的有效的Sql表达式

pattern:

通配符 描述 示例
% 包含零个或更多字符的任意字符串 title like '%1234%'
_ 任意单个字符 title like '_123'
[] 指定范围或集合中的任意单个字符 title like '[a-c]pp'
[^] 不属于指定范围或集合的任意单个字符 title like '[^c]pp'

escape_character:

没有默认值,有且必须有一个字符.

结果类型:

Boolean

例子:

对于下列数据

SqlServer--like

注意:

第5行和第6行的数据,其中第6行数据为:ab34f ,注意后面的空格.

第7行的数据为开始有空格.

采用不同的查询方法,查询到的数据结果如下:

1.select * from users where username like '%'

此时查询到所有结果.

2.select * from users where username like 'a%'

此时查询到所有以a为开头的数据信息

3.select * from users where username like '_123456'

此时查询到开头不确定,但后面确定的数据信息

4.select * from users where username like '[wa]%'

此时查询到以w或者a开头的数据信息的结果.

5.select * from users where username like '[^wa]%'

此时查询到不以w或者a开头的数据信息的结果

6.select * from users where username like 'ab/%%' escape '/'

此时,是将转义字符/后的第一个%也看做是查询的关键字.

结果如下:SqlServer--like

相关文章:

  • 2022-01-28
  • 2021-06-22
  • 2021-12-09
  • 2021-10-26
  • 2021-09-24
  • 2021-09-25
  • 2021-07-19
  • 2021-10-28
猜你喜欢
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
相关资源
相似解决方案