SQLite Query in non case sensitive alphabetical order [duplicate]

守給你的承諾、 提交于 2019-11-28 16:37:40

COLLATE goes before the order direction:

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

But you don't need the ASC -- that's the default so you could just as well use:

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

add COLLATE NOCASE after orderBy String.

db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy + " COLLATE NOCASE ASC");

here, order by ASC or DESC depends on your need.

This should work too I think:

db.rawQuery("SELECT "+ catName 
        +" FROM "+ tableName 
    +" ORDER BY lower("+ catName +");", null);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!