首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android - sqlite in子句使用数组中的值

Android - sqlite in子句使用数组中的值
EN

Stack Overflow用户
提问于 2012-02-09 07:34:56
回答 1查看 18.1K关注 0票数 26

我想执行一个sqlite查询:

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

in子句中的值需要从字符串数组中获取:

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

我怎样才能做到这一点呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-09 08:13:35

我相信一个简单的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;
票数 43
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9203261

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档