6.5.4 "[]" wildcard characters
The [] wildcard character is used to specify a series of characters, and a string that satisfies one of these characters and where the position appears in the "[]" wildcard character satisfies the query condition.
Of course, a variety of wildcard characters can also be used in combination. When using a variety of wildcard characters, be sure to clarify the matching criteria for their representations. such as "like ' 5[%]", where "%" within the "[]" wildcard is not understood as "%" wildcard character, but only for "%" characters. For the reader to understand, table 6-5 lists several query conditions and their matching criteria.
Table 6-5 combined wildcard characters and their matching criteria
Query criteria |
Matching Criteria |
Like ' 5[%] ' |
5% |
Like ' [_]n ' |
_n |
Like ' [A-CDF] ' |
A,b, c,d or F |
Like ' [-ACDF] ' |
-, A, C, D or F |
Like ' [[] ' |
[ |
Like '] ' |
] |
Like ' abc[_]d% ' |
Abc_d or Abc_d ... |
Like ' abc[def] ' |
ABCD, ABCE, or ABCF |
Instance 21 uses the ' [] ' wildcard character to query all courses that start with the "meter" or "live" character
In the course table, query for all course names (CNAME), Numbers (scount), and Exam time (ctest) information for all courses beginning with the "Count" or "live" character. Instance code:
SELECT CNAME, Scount, ctest from
COURSE
WHERE CNAME like ' [IPPF]% ' ORDER by
CNAME |
The results of the operation are shown in Figure 6.24.
|
Figure 6.24 All course names that start with "count" or "live" |
The character "^", which is listed in the "[]" wildcard, denotes a negative meaning.
Instance 22 uses the "[]" wildcard character to query for all course names that do not start with the "count" or "live" character
Query the course table for all course names (CNAME), Numbers (scount), and Exam time (ctest) information that do not begin with the "count" or "live" character. Instance code:
SELECT CNAME, Scount, ctest from
COURSE
WHERE CNAME like ' [^ IPPF]% ' ORDER by
CNAME |
The results of the operation are shown in Figure 6.25.
|
Figure 6.25 Any course name that does not start with the "count" or "live" word |
Of course, the not operator can also get the same result, at which point the SQL code is as follows.
SELECT CNAME, Scount, ctest from
COURSE
WHERE isn't CNAME like ' [IPPF]% ' ORDER by
CNAME |
The results of the operation are shown in Figure 6.26.
|
Figure 6.26 Any course name that does not start with the "count" or "live" word
|