20

我查询了提供排序数据的 sqlite3 数据库。数据根据varchar列“名称”进行排序。现在当我做查询

select * from tableNames Order by Name;

它提供这样的数据。

    笔
    订书机
    铅笔

意味着它正在考虑区分大小写的东西。我想要的方式如下

    笔
    铅笔
    订书机

那么我应该在 sqlite3 数据库中进行哪些更改以获得必要的结果?

相关字符串比较时如何将Sqlite3设置为不区分大小写?

4

4 回答 4

24

要对其进行排序,不区分大小写,您可以使用ORDER BY Name COLLATE NOCASE

于 2010-08-04T11:33:38.083 回答
13

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;

于 2009-07-29T22:34:59.400 回答
1
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 ;-)

于 2009-07-29T22:38:26.193 回答
0

在您的 SQLite 数据库中使用此语句:

PRAGMA case_sensitive_like = false
于 2010-11-08T17:42:44.627 回答