文章詳情頁
SQL實現(xiàn)模糊查詢的四種方法總結(jié)
瀏覽:5日期:2023-09-25 20:57:30
目錄一、一般模糊查詢二、利用通配符查詢1. _ 表示任意的單個字符2. % 表示匹配任意多個任意字符3. [ ]表示篩選范圍4. 查詢包含通配符的字符串
模糊查詢是針對字符串操作的,類似正則表達式,沒有正則表達式強大。
一、一般模糊查詢1. 單條件查詢
//查詢所有姓名包含“張”的記錄select * from student where name like '張'2. 多條件查詢
//查詢所有姓名包含“張”,地址包含四川的記錄select * from student where name like '張' and address like '四川'//查詢所有姓名包含“張”,或者地址包含四川的記錄select * from student where name like '張' or address like '四川'二、利用通配符查詢通配符:_ 、% 、[ ]
1. _ 表示任意的單個字符//查詢所有名字姓張,字長兩個字的記錄select * from student where name like '張_'//查詢所有名字姓張,字長三個字的記錄select * from student where name like '張__'2. % 表示匹配任意多個任意字符//查詢所有名字姓張,字長不限的記錄select * from student where name like '張%'//查詢所有名字姓張,字長兩個字的記錄select * from student where name like '張%'and len(name) = 23. [ ]表示篩選范圍//查詢所有名字姓張,第二個為數(shù)字,第三個為燕的記錄select * from student where name like '張[0-9]燕'//查詢所有名字姓張,第二個為字母,第三個為燕的記錄select * from student where name like '張[a-z]燕'//查詢所有名字姓張,中間為1個字母或1個數(shù)字,第三個為燕的名字。字母大小寫可以通過約束設(shè)定,不區(qū)分大小寫select * from student where name like '張[0-9a-z]燕'//查詢所有名字姓張,第二個不為數(shù)字,第三個為燕的記錄select * from student where name like '張[!0-9]燕'?//查詢名字除了張開頭妹結(jié)尾中間是數(shù)字的記錄select * from student where name not like '張[0-9]燕'4. 查詢包含通配符的字符串//查詢姓名包含通配符%的記錄?select * from student where name like '%[%]%'?? ??? ??? ??? ?//通過[]轉(zhuǎn)義//查詢姓名包含[的記錄?select * from student where name like '%/[%' escape '/'?? ?//通過指定'/'轉(zhuǎn)義//查詢姓名包含通配符[]的記錄?select * from student where name like '%/[/]%' escape '/'?? ?//通過指定'/'轉(zhuǎn)義到此這篇關(guān)于SQL實現(xiàn)模糊查詢的四種方法總結(jié)的文章就介紹到這了,更多相關(guān)SQL 模糊查詢內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
標簽:
MsSQL
數(shù)據(jù)庫
相關(guān)文章:
1. 省時又省力 用Oracle擴展SQL跟蹤數(shù)據(jù)2. 關(guān)于Oracle數(shù)據(jù)庫熱備份腳本深入剖析3. Access數(shù)據(jù)庫安全的幾個問題4. MySQL存儲過程例子(包含事務(wù)、參數(shù)、嵌套調(diào)用、游標循環(huán)等)5. MySQL雙主(主主)架構(gòu)配置方案6. MySQL 的啟動選項和系統(tǒng)變量實例詳解7. 一文帶你了解MySQL的左連接與右連接8. mysql-bin.000001文件的來源及處理方法9. Sql server數(shù)據(jù)庫開發(fā)常用匯總10. 如何遠程調(diào)用ACCESS數(shù)據(jù)庫
排行榜
