就像我们平时用的*和?,sql的like语句中,使用%和_来代表任意多个字符和一个字符
# %代表任意多个字符select * from user where username like '%huxiao';select * from user where username like 'huxiao%';select * from user where username like '%huxiao%';# %代表一个字符select * from user where username like '_';select * from user where username like '______';select * from user where username like 'huxia_';select * from user where username like 'h_xiao';# 如果我就真的要查%或者_,怎么办呢?使用escape,转义字符后面的%或_就不作为通配符了,注意前面没有转义字符的%和_仍然起通配符作用select username from gg_user where username like '%xiao/_%' escape '/';select username from gg_user where username like '%xiao/%%' escape '/';
1 楼 gaoyanglovejava 2011-04-20
很好。学习了。