三种方式哪种更高效?或者有更好的办法?
例如前台传过来的数据
ids = "1,2,23,43,1231,1239...."; 都是主键 若干多
方式1 使用in:
String ids = this.getPara("ids");
Db.delete("delete from table where id in(?)",ids);
方式2 使用循环:
String ids = this.getPara("ids");
String [] idArrs = ids.split(",");
for(String id:ids){
Db.deleteById(tableName,id);
}
方式3 使用batch
String ids = this.getPara("ids");
String [] idArrs = ids.split(",");
//转化为二维数组
Object[][] idArrs2Degree= 变二维(idArrs);
String sql = " delete from tableName id = ? ";
Db.batch(sql, idArrs2Degree,100);
-----------------------------------------
何种方式在数据量比较大的时候更加高效呢?