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]%'