<p>MySql的like语句中的通配符:百分号、下划线和escape</p><p></p><p>%代表任意多个字符</p><p>Sql代码 www.2cto.com </p><p>select * from user where username like &#39;%huxiao&#39;; </p><p></p><p>select * from user where username like &#39;huxiao%&#39;; </p><p></p><p>select * from user where username like &#39;%huxiao%&#39;; </p><p></p><p>_代表一个字符</p><p>Sql代码 </p><p>select * from user where username like &#39;_&#39;; </p><p></p><p>select * from user where username like &#39;huxia_&#39;; </p><p></p><p>select * from user where username like &#39;h_xiao&#39;; </p><p></p><p>如果我就真的要查%或者_,怎么办呢?使用escape,转义字符后面的%或_就不作为通配符了,注意前面没有转义字符的%和_仍然起通配符作用</p><p>Sql代码 </p><p>select username from gg_user where username like &#39;%xiao/_%&#39; escape &#39;/&#39;; </p><p></p><p>select username from gg_user where username like &#39;%xiao/%%&#39; escape &#39;/&#39;;</p>
RangeTime:0.007647s
RangeMem:204.84 KB
返回顶部 留言