在SQL语句中我们很容易实现一个delete from table where column in (字段一,字段二,字段三)的语句。
android中delete方法:
public int delete(String table, String whereClause, String[] whereArgs) {
acquireReference();
try {
SQLiteStatement statement = new SQLiteStatement(this, "DELETE FROM " + table +
(!TextUtils.isEmpty(whereClause) ? " WHERE " + whereClause : ""), whereArgs);
try {
return statement.executeUpdateDelete();
} finally {
statement.close();
}
} finally {
releaseReference();
}
}
但是当我们调用:
的时候就会出现删除数据异常,并不能删除电话号码为10010和10086的数据。
db.delete("table","phoneNumber in (?) ","‘10010’,‘10086’");
这样可以分开删除掉10010和10086的数据,前面的操作实际上是删除 这个字符串的 "10010,10086" 数据。
本文详细介绍了在Android开发中如何正确使用SQL DELETE语句,特别是针对带有IN子句的情况。通过具体示例,解释了如何避免因参数传递不当而导致的数据删除异常问题。
1538

被折叠的 条评论
为什么被折叠?



