如何删除行在SQLite与多个其中args? [英] How to delete rows in SQLite with multiple where args?
本文介绍了如何删除行在SQLite与多个其中args?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要删除满足多个条件中任何一个的行。
I want to delete rows which satisfy any of multiple conditions.
例如,我传递一个ID列表, code> ID (ID是唯一的)。
For example, I pass a list of IDs, and I want to delete all rows with these IDs
(IDs are unique).
这将是:
String[] ids = {"0", "1", "2", "3",...};
database.delete("rows" , "id=? OR id=? OR id=? OR id=? OR ..." , ids );
有没有办法压缩而没有多个 OR
$
Is there any way to do it compact without multiple OR
?
推荐答案
你可以通过 db.execSQL
方法和SQL的 IN 关键字。例如:
You may get it done through db.execSQL
method and SQL's IN keyword. For example:
String args = TextUtils.join(", ", ids);
db.execSQL(String.format("DELETE FROM rows WHERE ids IN (%s);", args));
这篇关于如何删除行在SQLite与多个其中args?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文