我做了一些谷歌搜索,我猜它是重复的,我想把max的值放在一个变量中,怎么做 我有以下查询:
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("select max(id) from tab1");
在oracle中例如它就像这样
Select max(id) into numb_var from tab1
答案 0 :(得分:3)
试试这个
Cursor cursor = db.rawQuery("Select max(id) into numb_var from tab1",null);
if (cursor != null) {
cursor.moveToFirst();
while(!cursor.isAfterLast()){
maxID = cursor.getInt(0);
cursor.moveToNext();
}
cursor.close();
}
}
你的maxID变量最大。
答案 1 :(得分:2)
试试这个:
int id = 0;
Cursor c = db.rawQuery("select max(id) as id from tab1", null);
while(c.moveToNext()) {
id = c.getInt(0);
}
//you have your id stored in id variable