我正在尝试对表中的所有列执行区分大小写的搜索,所以我做了类似的事情
Select * From mytable Where col1 || '--' || col2 || '--' || etc like '%SomeValue%'
但对于大写和小写它总是返回相同的结果。如果我这样做
Select * From mytable Where col1 like '%SomeValue%' OR col1 like '%SomeValue%' etc
我得到了想要的结果。这里的问题是我无法使用第二个查询,因为我有大约 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 http://www.sqlite.org/pragma.html#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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)