Java Reference
In-Depth Information
A pattern that contains a percent character ( % ) searches for strings that have zero or
more characters at the percent character's position in the pattern. For example, the next
query locates the rows of all the authors whose last name starts with the letter D :
SELECT AuthorID, FirstName, LastName
FROM Authors
WHERE LastName LIKE 'D%'
This query selects the two rows shown in Fig. 24.13—three of the five authors have a last
name starting with the letter D (followed by zero or more characters). The % symbol in the
WHERE clause's LIKE pattern indicates that any number of characters can appear after the
letter D in the LastName . The pattern string is surrounded by single-quote characters.
AuthorID
FirstName
LastName
1
Paul
Deitel
2
Harvey
Deitel
3
Abbey
Deitel
Fig. 24.13 | Authors whose last name starts with D from the Authors table.
Portability Tip 24.1
See the documentation for your database system to determine whether SQL is case sensitive
on your system and to determine the syntax for SQL keywords.
Portability Tip 24.2
Read your database system's documentation carefully to determine whether it supports the
LIKE operator as discussed here.
Pattern Matching: Any Character
An underscore ( _ ) in the pattern string indicates a single wildcard character at that posi-
tion in the pattern. For example, the following query locates the rows of all the authors
whose last names start with any character (specified by _ ), followed by the letter o , followed
by any number of additional characters (specified by % ):
SELECT AuthorID, FirstName, LastName
FROM Authors
WHERE LastName LIKE '_o%'
The preceding query produces the row shown in Fig. 24.14, because only one author in
our database has a last name that contains the letter o as its second letter.
AuthorID
FirstName
LastName
5
Michael
Morgano
Fig. 24.14 | The only author from the Authors table
whose last name contains o as the second letter.
 
Search WWH ::




Custom Search