欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SQL實(shí)現(xiàn)模糊查詢(xún)的四種方法小結(jié)

 更新時(shí)間:2024年03月29日 09:42:00   作者:浮生若夢(mèng)777  
在SQL中,模糊查詢(xún)是一種通過(guò)匹配字符串中的一部分或關(guān)鍵字來(lái)查詢(xún)數(shù)據(jù)的方法,本文主要介紹了SQL實(shí)現(xiàn)模糊查詢(xún)的四種方法小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下

一、一般模糊查詢(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) = 2

3. [ ]表示篩選范圍

//查詢(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)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論