[^](通配符 - 无需匹配的字符)(Transact-SQL)[^] (Wildcard - Character(s) Not to Match) (Transact-SQL)

适用于: SQL Server Azure SQL 数据库 Azure Synapse Analytics 并行数据仓库

匹配不在方括号 [^] 之间指定的范围或集合内的任何单个字符。Matches any single character that is not within the range or set specified between the square brackets [^]. 可以在涉及模式匹配的字符串比较(例如,LIKEPATINDEX)中使用这些通配符。These wildcard characters can be used in string comparisons that involve pattern matching, such as LIKE and PATINDEX.

示例Examples

A:简单示例A: Simple example

下面的示例使用 [^] 运算符查找 Contact 表中名字以 Al 开头且第三个字母不是 a 的前 5 名用户。The following example uses the [^] operator to find the top 5 people in the Contact table who have a first name that starts with Al and has a third letter that is not the letter a.

-- Uses AdventureWorks  
  
SELECT TOP 5 FirstName, LastName  
FROM Person.Person  
WHERE FirstName LIKE 'Al[^a]%';  

下面是结果集:Here is the result set.

FirstName     LastName
---------     --------
Alex          Adams
Alexandra     Adams
Allison       Adams
Alisha        Alan
Alexandra     Alexander

B:搜索字符范围B: Searching for ranges of characters

通配符集可以包含单个字符或字符范围,以及字符和范围的组合。A wildcard set can include single characters or ranges of characters as well as combinations of characters and ranges. 下面的示例使用 [^] 运算符来查找不以字母或数字开头的字符串。The following example uses the [^] operator to find a string that does not begin with a letter or number.

SELECT [object_id], OBJECT_NAME(object_id) AS [object_name], name, column_id 
FROM sys.columns 
WHERE name LIKE '[^0-9A-z]%';

下面是结果集:Here is the result set.

object_id     object_name   name    column_id
---------     -----------   ----    ---------
1591676718    JunkTable     _xyz    1

另请参阅See Also

LIKE (Transact-SQL) LIKE (Transact-SQL)
PATINDEX (Transact-SQL) PATINDEX (Transact-SQL)
%(通配符 - 需匹配的字符)(Transact-SQL) % (Wildcard - Character(s) to Match) (Transact-SQL)
(通配符 - 需匹配的字符)(Transact-SQL) [ ] (Wildcard - Character(s) to Match) (Transact-SQL)
_(通配符 - 匹配一个字符)(Transact-SQL)_ (Wildcard - Match One Character) (Transact-SQL)