📅  最后修改于: 2020-11-12 09:54:47             🧑  作者: Mango
SQLite GLOB运算符使用通配符仅将文本值与模式匹配。当搜索表达式与模式表达式匹配时,GLOB运算符将返回true,即1。
GLOB运算符遵循UNIX的语法,用于指定以下通配符。
句法:
星号符号的语法:
SELECT FROM table_name
WHERE column GLOB 'XXXX*'
or
SELECT FROM table_name
WHERE column GLOB '*XXXX*'
问号的语法:
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 '????'
例:
我们有一个名为“ STUDENT”的表,其中包含以下数据:
在这些示例中,WHERE语句的BLOB子句带有不同的“ *”和“?”运算符:
Statement | Description |
---|---|
WHERE FEES GLOB ‘200*’ | Finds any values that start with 200 |
WHERE FEES GLOB ‘*200*’ | Finds any values that have 200 in any position |
WHERE FEES GLOB ‘?00*’ | Finds any values that have 00 in the second and third positions |
WHERE FEES GLOB ‘2??’ | Finds any values that start with 2 and are at least 3 characters in length |
WHERE FEES GLOB’*2′ | Finds any values that end with 2 |
WHERE FEES GLOB ‘?2*3’ | Finds any values that have a 2 in the second position and end with a 3 |
WHERE FEES GLOB ‘2???3’ | Finds any values in a five-digit number that start with 2 and end with 3 |
范例1:
从“学生”表中选择所有记录,其中AGE以2开头:
SELECT * FROM STUDENT WHERE AGE GLOB '2*';
输出:
范例2:
从表“ STUDENT”中选择所有记录,其中FEES以2开头:
SELECT * FROM STUDENT WHERE FEES GLOB '2*';
输出: