English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
SQLite GLOB
operator is used to use wildcards to match text values with patterns. If the search expression can match the pattern expression, the GLOB operator will return true, which is1. Unlike the LIKE operator, GLOB is case-sensitive and follows the UNIX syntax to specify THE following wildcards.
The asterisk (*)*)
The question mark (?)
The asterisk (*)*)represents zero or more digits or characters. The question mark (?) represents a single digit or character.
The following is the basic syntax*
and?
.
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 '?XXXX?' or SELECT FROM table_name WHERE column GLOB '????'
You can combine multiple conditions using AND or OR operators. Here, XXXX can be any numeric or string value.
The following table lists many examples, showing WHERE clauses with LIKE subqueries having different*' and '?' operators.
serial number | declarations and descriptions |
---|---|
1 |
search for2values starting with 00 |
2 |
search for any value with2values starting with 00 |
3 |
search for any value with 00 at the second and third positions |
4 |
search for2starting and having a length of at least3any value with |
5 |
search for2any value ending with |
6 |
search for the second position with2and3any value ending with |
7 |
search for2and3any value in the five-digit number ending with |
Let's take a real example, considering the COMPANY table with the following records-
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 1 Paul 32 California 20000.0 2 Allen 25 Texas 15000.0 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0 6 Kim 22 South-Hall 45000.0 7 James 24 Houston 10000.0
Below is an example that will display all records from the COMPANY table where AGE starts with2The beginning.
sqlite> SELECT * FROM COMPANY WHERE AGE GLOB ''2*';
This will produce the following result.
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 2 Allen 25 Texas 15000.0 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0 6 Kim 22 South-Hall 45000.0 7 James 24 Houston 10000.0
Here is an example that displays all records in the COMPANY table where the ADDRESS contains a hyphen (-)-
sqlite> SELECT * FROM COMPANY WHERE ADDRESS GLOB '*-*';
This will produce the following result.
ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 4 Mark 25 Rich-Mond 65000.0 6 Kim 22 South-Hall 45000.0