在sqlite数据库中获得最大的id和存储值(get the max of id and store value in sqlite db)
我做了一些谷歌搜索,我想它的重复,我想把最大值,如果在一个变量,如何做到这一点,我有以下查询:
SQLiteDatabase db = this.getWritableDatabase(); db.execSQL("select max(id) from tab1");在oracle中,例如它是这样的
Select max(id) into numb_var from tab1I did some google search and i guess its duplicate, i want to put the value of max if in a variable, how to do that I have the below query:
SQLiteDatabase db = this.getWritableDatabase(); db.execSQL("select max(id) from tab1");In oracle for example its like this
Select max(id) into numb_var from tab1最满意答案
尝试这个
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变量中拥有最大值。
try this
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(); } }you'll have max in maxID variable.
更多推荐
发布评论