SQLite Glob clause
SQLite's GLOB operator is used to match text values in patterns specified by wildcards. If the search expression matches the pattern expression, the GLOB operator returns true, which is 1. Unlike the LIKE operator, GLOB is case-sensitive and follows UNIX syntax for the following wildcard characters.
Asterisk (*)
Question mark (?)
Asterisk (*) Represents zero, one, or more numbers or characters. The question mark (?) represents a single number or character. These symbols can be used in combination.
Syntax
* The basic syntax of and ? is as follows:
WHERE column GLOB 'XXXX*'
or
SELECT FROM table_name
WHERE column GLOB '*XXXX*'
or
SELECT FROM table_name
WHERE column GLOB 'XXXX?'
or
SELECT FROM table_name
WHERE column GLOB '?XXXX'
or
SELECT FROM table_name
WHERE column GLOB '?XXXX ?'
or
SELECT FROM table_name
WHERE column GLOB '????'
You can use the AND or OR operator to combine N quantity conditions. Here, XXXX can be any number or string value.
Examples
The following examples demonstrate the differences in GLOB clauses with '*' and '?' operators:
Statement | Description |
---|---|
Find any value starting with 200 | |
Find any value containing 200 at any position | |
Find any value whose second and third digits are 00 | |
Find any value that starts with 2 and has a length of at least Any value of 3 characters | |
Find any value ending with 2 | |
Find any value whose second digit is 2 and ends with 3 | |
Find any value that is 5 digits long and starts with 2 and ends with 3 |