sqlite 搜索多列

标签 sqlite select

我正在尝试对表中的所有列执行区分大小写的搜索,所以我做了这样的事情

从 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/

相关文章:

android - 在 sqlite 数据库更改时自动刷新 ListView - Android 聊天应用程序

Mysql 选择带有条件逻辑

MySQL 在进行 INSERT INTO 或 UPDATE 查询时保留 SELECT 语句

android - 从 sqlite android 排序 ListView 项目

c# - Xamarin Forms 无法创建 SQLite 数据库

sqlite - 事件的android中的“NOT”子句?

asp.net - 具有多个 LIKE 的选择命令

mysql - 改进我的查询

sql - 是否可以在 sql 查询期间设置标志

sqlite - kafka jdbc源连接器: time stamp mode is not working for sqlite3