当我使用此键时,它会给我一个错误,但是当我使用LENGTH时,它可以正常工作。我希望它可以在android sqlite上使用,因为它是最好的方法:
我只是想在将从数据库中选择的单词后删除空格。
public ArrayList<String> getCorrectList() {
// TODO Auto-generated method stub
Cursor c = db.rawQuery("SELECT REPLACE(Level_1, ' ', '') FROM " + TABLE, null);
ArrayList<String> resultsList = new ArrayList<String>();
try {
if (c != null) {
if (c.moveToFirst()) {
do {
String levelData = c.getString(c
.getColumnIndex("Level_1"));
resultsList.add("" + c.getColumnIndex("Level_1"));
} while (c.moveToNext());
}
}
} catch (SQLiteException e) {
Log.e("Database", "Cannot get List (" + e + ")");
}
Log.d("array", "List: " + resultsList);
Collections.shuffle(resultsList);
return resultsList;
}
答案 0 :(得分:0)
这在SQLite3 shell中运行良好:
e$ sqlite3
SQLite version 3.7.14.1 2012-10-04 19:37:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table t(a,b,c);
sqlite> select replace(a,' ', '') from t;
REPLACE
既是SQLite3中的函数,也是命令。也许db.rawQuery
正在解析查询并被REPLACE
弄糊涂了。试试这个:
db.rawQuery("select rtrim(replace(Level_1, ' ', '')) FROM " + TABLE, null);