在sqlite数据库中获得最大的id和存储值(get the max of id and store value in sqlite db)

编程入门 行业动态 更新时间:2024-10-28 16:30:59
在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 tab1

I 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.

更多推荐

本文发布于:2023-07-21 09:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1209035.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   id   sqlite   db   store

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!