我想通过字符串匹配从sqlite3数据库选择记录。但是如果我在where子句中使用'=',我发现sqlite3是区分大小写的。有人能告诉我如何使用字符串比较不区分大小写吗?
当前回答
像这样使用
"select * from $pwsXDataHistory where type = '$type' COLLATE NOCASE and $t_uStatus != '$DELETE' order by $t_name COLLATE NOCASE asc ");
其他回答
这不是特定于sqlite,但你可以这样做
SELECT * FROM ... WHERE UPPER(name) = UPPER('someone')
可以使用like查询将各自的字符串与表值进行比较。
Select column name from table_name where column name like '各自的比较值';
像这样使用
"select * from $pwsXDataHistory where type = '$type' COLLATE NOCASE and $t_uStatus != '$DELETE' order by $t_name COLLATE NOCASE asc ");
你可以这样做:
SELECT * FROM ... WHERE name LIKE 'someone'
(这不是解决方案,但在某些情况下非常方便)
"The LIKE operator does a pattern matching comparison. The operand to the right contains the pattern, the left hand operand contains the string to match against the pattern. A percent symbol ("%") in the pattern matches any sequence of zero or more characters in the string. An underscore ("_") in the pattern matches any single character in the string. Any other character matches itself or its lower/upper case equivalent (i.e. case-insensitive matching). (A bug: SQLite only understands upper/lower case for ASCII characters. The LIKE operator is case sensitive for unicode characters that are beyond the ASCII range. For example, the expression 'a' LIKE 'A' is TRUE but 'æ' LIKE 'Æ' is FALSE.)."
如果列的类型是char,那么你需要用空格来附加你正在查询的值,请参考这里的问题。除此之外,还可以使用COLLATE NOCASE或其他解决方案(upper()等)。
推荐文章
- SQLite数据库文件使用什么扩展名重要吗?
- 无法加载DLL 'SQLite.Interop.dll'
- 快速简单的方法迁移SQLite3到MySQL?
- 我如何做一个不区分大小写的字符串比较?
- Oracle中不区分大小写的搜索
- 在Ubuntu上安装sqlite3-ruby错误
- sqlite3。ProgrammingError:提供的绑定数量不正确。当前语句使用1,并提供了74个
- SQLite有。net / c#包装器吗?
- 如何在Django ORM中查询不区分大小写的数据?
- Android开发有什么好的ORM工具吗?
- 不区分大小写的搜索
- 如何在SQLite中看到表的结构?
- Android中使用的SQLite版本?
- 如何在JavaScript中执行不区分大小写的字符串排序数组?
- Core Data vs SQLite 3