SQLite 查询不区分大小写字母顺序

发布于 2024-11-06 11:44:42 字数 353 浏览 3 评论 0原文

我想做的就是按字母顺序抓取内容并忽略大写字母。

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

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

android.database.sqlite.SQLiteException:靠近“COLLATE”:语法错误:,编译时:从 testTable COLLATE NOCASE ASC 中选择艺术家

All I want to do is grab the stuff in alphabetical order and ignore the capital letters.

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

This is the code I'm using above, but it always gives me an SQLite exception saying that COLLATE is a syntax error.

android.database.sqlite.SQLiteException: near "COLLATE": syntax error: , while compiling: SELECT Artist FROM testTable COLLATE NOCASE ASC

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余生共白头 2024-11-13 11:44:42

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);

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);
不爱素颜 2024-11-13 11:44:42

在 orderBy String 之后添加 COLLATE NOCASE

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

这里,按 ASC 或 DESC 顺序取决于您的需要。

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.

有深☉意 2024-11-13 11:44:42

我认为这也应该有效:

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

This should work too I think:

db.rawQuery("SELECT "+ catName 
        +" FROM "+ tableName 
    +" ORDER BY lower("+ catName +");", null);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文