MySql的like语句中的通配符:百分号、下划线和escape

%代表任意多个字符
_代表一个字符
escape,转义字符后面的%或_,使其不作为通配符,而是普通字符匹配
 
数据库数据如下:


1.查找名字中以Lucy的字段

查询语句:

select * from `user` where name like 'Lucy%'

结果:

2、查询名字是“Lucy”开头且后面只有一个字符的字段

查询语句:

select * from `user` where name like 'Lucy_'

查询结果:

Mysql中的like模糊查询

3、查找名字中以“Lucy_”开始的字段

查询语句:

select * from `user` where name like 'Lucy/_%' escape'/'

查询结果:

Mysql中的like模糊查询

4、查询名字中以“Lucy”开始,中间含有“_”,以“2”结束的字段

查询语句:

select * from `user` where name like 'Lucy%/_%2' ESCAPE '/'

查询结果:

Mysql中的like模糊查询

 

相关文章:

  • 2022-12-23
  • 2022-02-01
  • 2021-08-02
  • 2021-09-23
  • 2022-12-23
  • 2021-08-07
  • 2021-09-03
  • 2022-12-23
猜你喜欢
  • 2021-05-14
  • 2021-10-04
  • 2022-02-06
  • 2022-12-23
  • 2021-11-29
  • 2021-11-08
相关资源
相似解决方案