query with LIKE but case sensitive

旧巷老猫 提交于 2020-01-24 10:03:47

问题


Why isn't my query case sensitive?

Select * from MyTable where name like '%Ann%'

shows record 1 correctly:

Record1= John, Ann, Jack

but shows also record 2:

Record2: Jack, Susanne, Jim

回答1:


You could execute PRAGMA case_sensitive_like = on, but this would affect all LIKEs used in your program, and disable any index optimizations for prefix searches.

A better idea would be to replace LIKE with GLOB:

SELECT * FROM MyTable WHERE Name GLOB '*Ann*'



回答2:


[Copied from rbedger's answer:]

You can use the UPPER keyword on your case insensitive field then upper-case your like statement

SELECT * FROM mytable 
WHERE caseSensitiveField like 'test%' 
AND UPPER(caseInsensitiveField) like 'G2%'



回答3:


the SQL LIKE is case-insensitive(thnks to CL ) So, on some SQL implementations you can do case Sensitive SQL query Searches

check this too: Case insensitive searching in Oracle



来源:https://stackoverflow.com/questions/22310981/query-with-like-but-case-sensitive

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