模糊查询-通配符

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 '\'表示反斜杠作为转义字符

 

posted on 2021-03-15 09:47  jesse_zhao  阅读(977)  评论(0)    收藏  举报

导航