SQLite 喜欢 % 和 _ [英] SQLite Like % and _
问题描述
我无法弄清楚 SQLite like
语句中下划线字符的作用.通配符 %
可能与大多数其他 SQL 数据库中的相同.
I can't figure out what the underscore character does in an SQLite like
statement.
The wildcard character, %
, is probably the same as in most other SQL databases.
那么,_
字符有什么作用?
So, what does the _
character do?
推荐答案
下划线也与大多数其他 SQL 数据库中的相同,匹配任何单个字符(即与 .
中的相同)正则表达式).来自精美手册:
The underscore is also the same as in most other SQL databases and matches any single character (i.e. it is the same as .
in a regular expression). From the fine manual:
LIKE 模式中的下划线(_")匹配字符串中的任何单个字符.
An underscore ("_") in the LIKE pattern matches any single character in the string.
例如:
-- The '_' matches the single 'c'
sqlite> select 'pancakes' like 'pan_akes';
1
-- This would need '__' to match the 'ca', only one '_' fails.
sqlite> select 'pancakes' like 'pan_kes';
0
-- '___' also fails, one too many '_'.
sqlite> select 'pancakes' like 'pan___kes';
0
为了确保结果有意义:SQLite 使用0 和 1 表示布尔值.
And just to make sure the results make sense: SQLite uses zero and one for booleans.
这篇关于SQLite 喜欢 % 和 _的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!