帶條件的查詢—模糊查詢

模糊查詢(都是針對字符串操做的)

模糊查詢有點相似於正則表達式,可是他沒有正則表達式那麼強大。正則表達式

通配符:  _   、 % 、   []  、   ^   spa

    _  表示任意的單個字符串。

select * from Student_Info where Name like '張_'

這樣就找出Student_Info 表中 Name列 張某的名字,兩個字;  而不會查出張某某的名字。code

還有一種辦法就是字符串

select * from Student_Info where Name like '張%' and len(Name)=2

怎麼查個張某某,三個字的class

select * from Student_Info where Name like '張__'

%匹配任意多個 任意字符

查詢 名字 中只要第一個字是 張。  無論有多少個字符。date

select * from Student_Info where Name like '張%'

 

[] 表示 篩選的範圍。

查詢姓張的 中間是個數字 第三個是漢字。select

select * from Student_Info where Name like '張[0-9]三'

查詢姓張的 中間是個數字或者是字母,  第三個是漢字。查詢

select * from Student_Info where Name like '張[0-9][a-z]三'

 

^  表示非

查詢張 某三,  就是中間不能是數字。di

select * from Student_Info where Name like '張[0-9]三'

 

 

拓展  替換 REPLACE  關鍵字

update Student_Info set Name=replace(Name,'張','李')

這樣就把 姓張的 所有替換爲姓李的。co

相關文章
相關標籤/搜索