我查询了提供排序数据的 sqlite3 数据库。数据根据varchar
列“名称”进行排序。现在当我做查询
select * from tableNames Order by Name;
它提供这样的数据。
笔 订书机 铅笔
意味着它正在考虑区分大小写的东西。我想要的方式如下
笔 铅笔 订书机
那么我应该在 sqlite3 数据库中进行哪些更改以获得必要的结果?
我查询了提供排序数据的 sqlite3 数据库。数据根据varchar
列“名称”进行排序。现在当我做查询
select * from tableNames Order by Name;
它提供这样的数据。
笔 订书机 铅笔
意味着它正在考虑区分大小写的东西。我想要的方式如下
笔 铅笔 订书机
那么我应该在 sqlite3 数据库中进行哪些更改以获得必要的结果?
要对其进行排序,不区分大小写,您可以使用ORDER BY Name COLLATE NOCASE
The SQLite Datatypes documentation discusses user-defined collation sequences. Specifically you use COLLATE NOCASE to achieve your goal.
They give an example:
CREATE TABLE t1(
a, -- default collation type BINARY
b COLLATE BINARY, -- default collation type BINARY
c COLLATE REVERSE, -- default collation type REVERSE
d COLLATE NOCASE -- default collation type NOCASE
);
and note that:
-- Grouping is performed using the NOCASE collation sequence (i.e. values -- 'abc' and 'ABC' are placed in the same group). SELECT count(*) GROUP BY d FROM t1;
select * from tableNames Order by lower(Name);
Michael van der Westhuizen explains in his comment below why this is not a good way. I am leaving this answer up so as to preserve his comment and to serve as a warning to others who might have the same 'bright' idea I had ;-)
在您的 SQLite 数据库中使用此语句:
PRAGMA case_sensitive_like = false