close
文章出處

MySql的like語句中的通配符:百分號、下劃線和escape
 
%代表任意多個字符
Sql代碼    www.2cto.com  
select * from user where username like '%huxiao';   
  
select * from user where username like 'huxiao%';   
  
select * from user where username like '%huxiao%';   
 
 _代表一個字符
Sql代碼  
select * from user where username like '_';   
  
select * from user where username like 'huxia_';   
  
select * from user where username like 'h_xiao';   
 
 如果我就真的要查%或者_,怎么辦呢?使用escape,轉義字符后面的%或_就不作為通配符了,注意前面沒有轉義字符的%和_仍然起通配符作用
Sql代碼  
select username from gg_user where username like '%xiao/_%' escape '/';   
  
select username from gg_user where username like '%xiao/%%' escape '/'; 

不含病毒。www.avast.com
arrow
arrow
    全站熱搜

    AutoPoster 發表在 痞客邦 留言(0) 人氣()