为什么我们需要SQLite中的GLOB子句?

时间:2022-09-02 00:22:22

I'm an Android developer and recently came across the GLOB clause in SQLite. I cannot understand why we need GLOB given that LIKE is already in place.

我是Android开发人员,最近在SQLite中遇到了GLOB子句。我不明白为什么我们需要GLOB,因为LIKE已经存在。

Both clauses have wildcards to represent single and multiple characters. The only difference is that GLOB is case sensitive.

这两个子句都有通配符来表示单个和多个字符。唯一的区别是GLOB区分大小写。

But is that all? Are there any queries where LIKE is a bad or inappropriate choice? Are there any cases where we absolutely have to use GLOBE vs LIKE or vice versa?

但这就是全部吗?是否有任何疑问LIKE是一个坏或不合适的选择?在任何情况下,我们绝对必须使用GLOBE vs LIKE,反之亦然?

1 个解决方案

#1


19  

Case sensitivity is useful by itself, because this works better with normal indexes.

区分大小写本身很有用,因为这对普通索引更有效。

Additionally, GLOB supports character classes:

另外,GLOB支持字符类:

Globbing rules:

全球规则:

* Matches any sequence of zero or more characters.

*匹配零个或多个字符的任何序列。

? Matches exactly one character.

?只匹配一个字符。

[...] Matches one character from the enclosed list of characters.

[...]匹配附带的字符列表中的一个字符。

[^...] Matches one character not in the enclosed list.

[^ ...]匹配一个不在随附列表中的字符。

With the [...] and [^...] matching, a ] character can be included in the list by making it the first character after [ or ^. A range of characters can be specified using -. Example: [a-z] matches any single lower-case letter. To match a -, make it the last character in the list.

通过[...]和[^ ...]匹配,一个]字符可以包含在列表中,使其成为[或^之后的第一个字符。可以使用 - 指定一系列字符。示例:[a-z]匹配任何单个小写字母。要匹配 - ,请将其设为列表中的最后一个字符。

#1


19  

Case sensitivity is useful by itself, because this works better with normal indexes.

区分大小写本身很有用,因为这对普通索引更有效。

Additionally, GLOB supports character classes:

另外,GLOB支持字符类:

Globbing rules:

全球规则:

* Matches any sequence of zero or more characters.

*匹配零个或多个字符的任何序列。

? Matches exactly one character.

?只匹配一个字符。

[...] Matches one character from the enclosed list of characters.

[...]匹配附带的字符列表中的一个字符。

[^...] Matches one character not in the enclosed list.

[^ ...]匹配一个不在随附列表中的字符。

With the [...] and [^...] matching, a ] character can be included in the list by making it the first character after [ or ^. A range of characters can be specified using -. Example: [a-z] matches any single lower-case letter. To match a -, make it the last character in the list.

通过[...]和[^ ...]匹配,一个]字符可以包含在列表中,使其成为[或^之后的第一个字符。可以使用 - 指定一系列字符。示例:[a-z]匹配任何单个小写字母。要匹配 - ,请将其设为列表中的最后一个字符。