Search
Friday, April 4, 2008
Pattern Matching
pattern matching:
• % (percent mark): This wildcard represents zero to many characters. For example,
WHERE title LIKE '%C# 2008%' finds all book titles containing the text “C# 2008,”
regardless of where in the title that text occurs—at the beginning, middle, or end.
In this case, book titles such as “C# 2008: An Introduction,” “Accelerated C# 2008,”
and “Beginning C# 2008 Databases” will be listed.
• _ (underscore): A single underscore represents any single character. By using this
wildcard character, you can be very specific in your search about the character
length of the data you seek. For example, WHERE au_fname LIKE '_ean' finds all the
first names that consist of four letters and that end with “ean” (Dean, Sean, and so
on). WHERE au_fname LIKE 'a___n' finds all the first names that begin with “a” and
end with “n” and have any other three characters in between, for example, allan,
amman, aryan, and so on.
• [ ] (square brackets): These specify any single character within the specified range,
such as [a-f], or set, such as [abcdef] or even [adf]. For example, WHERE au_lname
LIKE '[C-K]arsen' finds author last names ending with “arsen” and starting with
any single character between “C” and “K,” such as Carsen, Darsen, Larsen, Karsen,
and so on.
• [^] (square brackets and caret): These specify any single character not within the
specified range, such as [^a-f], or set, such as [^abcdef]. For example, WHERE
au_lname LIKE 'de[^l]%' retrieves all author last names starting with “de,” but
the following letter cannot be “l.”
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment