使用escape模糊查询包含关键字符字段

在sql like语句中,比如

select * from user where username like '%nihao%',select * from user where username like '_nihao',

其中%做为通配符通配多个,_作为通配符通配一个

 

如果要真的去查询username中含有 % _ 的,需要使他们不再作为通配符

将% _ 在like中转义,拿_为例,

转义前:select * from user where username like '_nihao',

转义后:select * from user where username like '/_nihao' escape '/',意思就是说/之后的_不作为通配符

猜你喜欢

转载自xiaoxiaoher.iteye.com/blog/2419970