views:

33

answers:

2

The SQL wildcards "%" and "_" are well documented and widely known. However as w3schools explains, there are also "charlist" style wildcards for matching a single character within or outside a given range, for example to find all the people called Carl but not those called Earl:

select * from Person where FirstName like '[A-D]arl'

... or to find the opposite, use either:

select * from Person where FirstName like '[!A-D]arl'

or (depending on the RDBMS, presumably):

select * from Person where FirstName like '[^A-D]arl'

Is this type of wildcard part of the SQL-92 standard, and what databases actually support it? For example:

  • Oracle 11g doesn't support it
  • SQL Server 2005 supports it, with the negation operator being "^" (not "!")
+1  A: 

The "charlist" operators look like regular expressions, or a limited subset of them. AFAIK there's no regular expression syntax specified in SQL-92 although many databases support regex's, and HOW they support it varies. Oracle, for example, has functions to do regular expression comparisons and substitutions. Don't know how others do it.

Share and enjoy.

Bob Jarvis
+1  A: 

The SQL-99 Standard has a SIMILAR TO predicate which uses "charlist" style as well as the "%" and "_" wildcard characters.

Nothing similar (no pun intended) in the SQL-92 Standard, though.

onedaywhen