簡體   English   中英

Android - 使用數組中的值的 sqlite in 子句

[英]Android - sqlite in clause using values from array

我想執行一個sqlite查詢:

select * from table_name where id in (23,343,33,55,43);

in子句中的值需要從字符串數組中獲取:

String values[] = {"23","343","33","55","43"}

我怎樣才能做到這一點?

我相信一個簡單的toString()可以解決大部分問題:

String values[] = {"23","343","33","55","43"};
String inClause = values.toString();

//at this point inClause will look like "[23,343,33,55,43]"
//replace the brackets with parentheses
inClause = inClause.replace("[","(");
inClause = inClause.replace("]",")");

//now inClause will look like  "(23,343,33,55,43)" so use it to construct your SELECT
String select = "select * from table_name where id in " + inClause;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM