Select語句—包含萬用字元的查詢

來源:互聯網
上載者:User
1、/*萬用字元_(底線)*/
/*_
功能:代表一個字元
用法:只能用在where字句中,通常_與運算子like配合使用
*/
/*查詢LastName中第三個字元是a的人*/
select LastName from Employees where LastName like '__a%';

/*查詢LastName中第三個字元是a,並且LastName只有三個字元*/
select LastName from Employees where LastName like '__a';

2、/*萬用字元[]*/
/*[]用來限定單個字元界定於指定的範圍或集合中*/

select City from Customers where City like '[A-E]%'
select City from Customers where City like '[MC]%'
/*查詢電話號碼 :第一位為2-4的電話號碼*/
select Phone from Customers where Phone like '[2-4]%'
/*查詢電話號碼 :第一位為2或4的電話號碼*/
select Phone from Customers where Phone like '[24]%'

/*查詢城市 :第一字元為B,第二字元為A或E的城市*/
select City from Customers where City like 'B[AE]%'

/*重點注意:查詢姓名 查得姓名完全是中文文字(不包含任何英文或數字)*/
select name from my where name not like '%[a-z]%' and name not like '%[0-9]%'

3、/*[^] 不在指定的範圍或集合中 相當於“非[]”*/
/*如:
[^A-D] [^1-9]
[^ACD] [^135]
*/
/*第一個字元不包括A、B、C、D*/
select LastName from Employees where LastName like '[^A-D]%'
/*第一個字元不是A、C、D*/
select LastName from Employees where LastName like '[^ACD]%'

/*查詢LastName中第三個字元是a,並且LastName只有三個字元*/
select LastName from Employees where LastName like '__a';

2、/*萬用字元[]*/
/*[]用來限定單個字元界定於指定的範圍或集合中*/

select City from Customers where City like '[A-E]%'
select City from Customers where City like '[MC]%'
/*查詢電話號碼 :第一位為2-4的電話號碼*/
select Phone from Customers where Phone like '[2-4]%'
/*查詢電話號碼 :第一位為2或4的電話號碼*/
select Phone from Customers where Phone like '[24]%'

/*查詢城市 :第一字元為B,第二字元為A或E的城市*/
select City from Customers where City like 'B[AE]%'

/*重點注意:查詢姓名 查得姓名完全是中文文字(不包含任何英文或數字)*/
select name from my where name not like '%[a-z]%' and name not like '%[0-9]%'

3、/*[^] 不在指定的範圍或集合中 相當於“非[]”*/
/*如:
[^A-D] [^1-9]
[^ACD] [^135]
*/
/*第一個字元不包括A、B、C、D*/
select LastName from Employees where LastName like '[^A-D]%'
/*第一個字元不是A、C、D*/
select LastName from Employees where LastName like '[^ACD]%'

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.