文章詳情頁(yè)
SQL實(shí)現(xiàn)模糊查詢(xún)的四種方法總結(jié)
瀏覽:3日期:2023-09-25 20:57:30
目錄一、一般模糊查詢(xún)二、利用通配符查詢(xún)1. _ 表示任意的單個(gè)字符2. % 表示匹配任意多個(gè)任意字符3. [ ]表示篩選范圍4. 查詢(xún)包含通配符的字符串
模糊查詢(xún)是針對(duì)字符串操作的,類(lèi)似正則表達(dá)式,沒(méi)有正則表達(dá)式強(qiáng)大。
一、一般模糊查詢(xún)1. 單條件查詢(xún)
//查詢(xún)所有姓名包含“張”的記錄select * from student where name like '張'2. 多條件查詢(xún)
//查詢(xún)所有姓名包含“張”,地址包含四川的記錄select * from student where name like '張' and address like '四川'//查詢(xún)所有姓名包含“張”,或者地址包含四川的記錄select * from student where name like '張' or address like '四川'二、利用通配符查詢(xún)通配符:_ 、% 、[ ]
1. _ 表示任意的單個(gè)字符//查詢(xún)所有名字姓張,字長(zhǎng)兩個(gè)字的記錄select * from student where name like '張_'//查詢(xún)所有名字姓張,字長(zhǎng)三個(gè)字的記錄select * from student where name like '張__'2. % 表示匹配任意多個(gè)任意字符//查詢(xún)所有名字姓張,字長(zhǎng)不限的記錄select * from student where name like '張%'//查詢(xún)所有名字姓張,字長(zhǎng)兩個(gè)字的記錄select * from student where name like '張%'and len(name) = 23. [ ]表示篩選范圍//查詢(xún)所有名字姓張,第二個(gè)為數(shù)字,第三個(gè)為燕的記錄select * from student where name like '張[0-9]燕'//查詢(xún)所有名字姓張,第二個(gè)為字母,第三個(gè)為燕的記錄select * from student where name like '張[a-z]燕'//查詢(xún)所有名字姓張,中間為1個(gè)字母或1個(gè)數(shù)字,第三個(gè)為燕的名字。字母大小寫(xiě)可以通過(guò)約束設(shè)定,不區(qū)分大小寫(xiě)select * from student where name like '張[0-9a-z]燕'//查詢(xún)所有名字姓張,第二個(gè)不為數(shù)字,第三個(gè)為燕的記錄select * from student where name like '張[!0-9]燕'?//查詢(xún)名字除了張開(kāi)頭妹結(jié)尾中間是數(shù)字的記錄select * from student where name not like '張[0-9]燕'4. 查詢(xún)包含通配符的字符串//查詢(xún)姓名包含通配符%的記錄?select * from student where name like '%[%]%'?? ??? ??? ??? ?//通過(guò)[]轉(zhuǎn)義//查詢(xún)姓名包含[的記錄?select * from student where name like '%/[%' escape '/'?? ?//通過(guò)指定'/'轉(zhuǎn)義//查詢(xún)姓名包含通配符[]的記錄?select * from student where name like '%/[/]%' escape '/'?? ?//通過(guò)指定'/'轉(zhuǎn)義到此這篇關(guān)于SQL實(shí)現(xiàn)模糊查詢(xún)的四種方法總結(jié)的文章就介紹到這了,更多相關(guān)SQL 模糊查詢(xún)內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
標(biāo)簽:
MsSQL
數(shù)據(jù)庫(kù)
相關(guān)文章:
1. mysql-joins具體用法說(shuō)明2. Oracle中PL/SQL編程對(duì)系統(tǒng)性能的影響3. MySQL慢查詢(xún)以及解決方案詳解4. Oracle如何編寫(xiě)一個(gè)sqlldr實(shí)例5. 實(shí)例講解Oracle數(shù)據(jù)庫(kù)設(shè)置默認(rèn)表空間問(wèn)題6. MySQL的binlog日志使用詳解7. Oracle 數(shù)據(jù)庫(kù)集中復(fù)制方法逐步精細(xì)8. Oracle和MySQL的一些簡(jiǎn)單命令對(duì)比9. oracle正則表達(dá)式多項(xiàng)匹配時(shí)相似項(xiàng)有優(yōu)先級(jí)詳解10. 淺談創(chuàng)建Oracle數(shù)據(jù)庫(kù)連接的兩種方法
排行榜
