sqlite search multiple column

人盡茶涼 提交于 2021-02-08 05:04:55

问题


am trying to perform a case sensitive serach of all columns in a table, so i did somthing like this

Select * From mytable Where col1 || '--' || col2 || '--' || etc like '%SomeValue%'

but it alwas return the same result for both upper case and lower case. if i do this

Select * From mytable Where col1 like '%SomeValue%' OR col1 like '%SomeValue%' etc

i get the desired result. The problems here is that i cannot use this second query as i have about 36 columns to search, and writing col1 like '%SomeValue%' up to 36 times would be unecessary.

does anyone have any solution?


回答1:


One solution is to use glob instead of 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> 

Another solution is to use 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> 


来源:https://stackoverflow.com/questions/12737396/sqlite-search-multiple-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!