sql like語句通配符百分號、下劃線與escape用法

在sql查詢中,像*和?,sql的like語句中,使用%和_來表明任意多個字符和一個字符  sql

# %表明任意多個字符   spa

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 '/'; 
相關文章
相關標籤/搜索