模糊查詢-通配符


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 '\'表示反斜杠作為轉義字符

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM