LIKE语句通配符:%|_|[]

%代表0个或多个字符

select * from cif_user cu where cu.name like '%cai%'  ---名字中存在cai
select * from cif_user cu where cu.name like '%cai'    ---名字以cai结尾
select * from cif_user cu where cu.name like 'cai%'    ---名字以cai开头
select * from cif_user cu where cu.name like '%c%' and cu.name like '%i%'    ---名字既存在c又存在i
select * from cif_user cu where cu.name like '%c%ai%'  --与上面的区别在于筛选不出“...cai...”的情况

_代替一个字符

select * from cif_user cu where cu.name like '_ai'

charlist字符集合:[] 代表括号中任意一个字符

select * from cif_user cu where cu.name like '[a,b,c]%';   --查询名字以a或b或c开头的数据
select * from cif_user cu where cu.name like '[!a,b,c]%';   ---查询名字不是以a,b,c开头的数据
select * from cif_user cu where cu.name like '[^a,b,c]%';   ---查询名字不是以a,b,c开头的数据

猜你喜欢

转载自blog.csdn.net/LittleGirl_orBoy/article/details/105762310
今日推荐