使用"IN"将数组作为参数传递给要在SQL查询中使用的参数.命令 [英] passing an Array as a Parameter to be used in a SQL Query using the "IN" Command

查看:613
本文介绍了使用"IN"将数组作为参数传递给要在SQL查询中使用的参数.命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家下午好,

我有一个关于SQL查询的问题.是否可以使用"IN"命令将数组用作查询的参数?

I have a question concerning on SQL Queries. is it possible to use an array as a parameter to a query using the "IN" command?

例如,

int x = {2,3,4,5}

int x = {2,3,4,5}

更新'table_name'设置'field'=数据WHERE field_ID IN(x)

UPDATE 'table_name' set 'field' = data WHERE field_ID IN (x)

我要求这样做的原因是,当我必须更新数据库中的数据时,要避免使用迭代SQL语句. 我还考虑过对UPDATE查询中的每个语句使用a,但是我不知道如果更新了100多个记录,它是否会减慢系统的运行速度,是否会影响查询的性能.

the reason I am asking this is to avoid an iterative SQL Statement when I have to update data in a database. I also thought of using a for each statement in for the UPDATE Query but I don't know if it will affect the performance of the query if it will slow down the system if ever 100+ records are updated.

我正在使用VB.Net. 我的数据库是MySQL Workbench.

I am using VB.Net btw. My Database is MySQL Workbench.

推荐答案

我已经找到答案了.我只需要将每个元素转换为字符串,然后将每个元素用,"连接起来即可.所以我要传递的参数将是一个字符串.

I have gotten the answer. I just simply need to convert each elements to a String then concatenate it with a "," for each element. so the parameter that i will pass will be a string.

答案: 整数x = {2,3,4,5} 会变成 字符串x ="2,3,4,5"

ANSWER: int x = {2,3,4,5} will become string x = "2,3,4,5"

我的查询字符串将变为"UPDATE tablename SET field = value WHERE ID IN(& x&")"

My Query string will become "UPDATE tablename SET field=value WHERE ID IN("&x&")"

感谢所有提供帮助的人.

Thank you to all who helped.

这篇关于使用"IN"将数组作为参数传递给要在SQL查询中使用的参数.命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆