This question already has answers here:
How to use SQL Order By statement to sort results case insensitive?

(3个答案)


4年前关闭。




我要做的就是按字母顺序抓取东西,而忽略大写字母。
db.rawQuery("SELECT " + catName + " FROM "+tableName+" ORDER BY "+catName+" ASC COLLATE NOCASE;", null);

这是我在上面使用的代码,但是它总是给我一个SQLite异常,表明COLLATE是语法错误。

最佳答案

COLLATE在订单方向之前:

db.rawQuery("SELECT " + catName
           + " FROM " +tableName
        +" ORDER BY "+catName+" COLLATE NOCASE ASC;", null);

但是您不需要ASC-这是默认设置,因此您可以很好地使用:
db.rawQuery("SELECT "+ catName
            +" FROM "+ tableName
        +" ORDER BY "+ catName +" COLLATE NOCASE;", null);

10-07 17:13