6、模糊查詢--通配

% : 任意0個或多個字符
select * from custbaseinfo where idaddr like '%安徽%' --idaddr是安徽的
_ :下划線_替代任意單個字符
SELECT * FROM fundinfo WHERE fundid like '_0%' --fundid字段第二個字母是0的fundinfo數據
[A-F]:字符是在A到F之間的任意字符 (A B C D E F) ---與正則表達式的規則一致
select *from custbaseinfo where custname like '_[A-F]%' --custname中第二個字符是在A B C D E F中的任意字符 select * from fundinfo where fundid like '[2-3]%' --fundid字段的第一個字符是2 、3中任意一個字符都行
[^A-F]:字符是不在A到F之間的任意字符 (A B C D E F)---與正則表達式規則一致
select *from custbaseinfo where custname like '_[^A-F]%' --custname中第二個字符是在A B C D E F中之外的任意字符 select * from fundinfo where fundid like '[^2-3]%' --fundid字段的第一個字符是2 、3中之外的任意字符
【A,F】:字符是A或者F --與正則表達式規則一致
特殊說明:
因為% 、 _ 是屬於特殊字符,有特殊含義,如果要查詢含有這些字符的字段,需要使用反斜杠\進行轉義
select * from customer where custname like '%\%%' ESCAPE '\' --escape '\'表示反斜杠作為轉義字符