我正在尝试对表中的所有列执行区分大小写的搜索,所以我做了这样的事情
从 mytable 中选择 * 其中 col1 || '--' ||列2 || '--' ||等,如“%SomeValue%”
但对于大写和小写它总是返回相同的结果。如果我这样做
从 mytable 中选择 * 其中 col1 like '%SomeValue%' 或 col1 like '%SomeValue%' 等
我得到了想要的结果。这里的问题是我无法使用第二个查询,因为我有大约 36 列要搜索,并且将 col1 like '%SomeValue%'
写入最多 36 次是不必要的。
谁有解决办法吗?
最佳答案
一种解决方案是使用 glob
而不是 like
sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') like '%Bar%';
table|t|t|2|CREATE TABLE t (a)
sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') glob '*Bar*';
sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') glob '*bar*';
table|t|t|2|CREATE TABLE t (a)
sqlite>
另一个解决方案是使用 pragma case_sensitive_like
sqlite> PRAGMA case_sensitive_like = 1;
sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') like '%Bar%';
sqlite> select * from sqlite_master where ('foo' || '--' || 'bar') like '%bar%';
table|t|t|2|CREATE TABLE t (a)
sqlite>
关于sqlite 搜索多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12737396/