本文介绍了将数组插入sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用Insert语句将任何数组直接插入表格 如果是,请告诉我...... br $> b $ b 我不想创建任何函数... i只想使用简单的sql查询...
解决方案您可以插入分隔符限制字符串的所有元素。但是,我认为这不会有太大的帮助。 最好将数组的元素逐个插入表中。
不,不是作为一个用于不同行的值数组 - SQL没有任何数组概念,因此它不会理解它们。这是可能的(虽然PITA通过由逗号分隔值组成的字符串来完成此操作,但最好是作为存储过程完成,而不是通过INSERT语句。 如果它是你想要的varBinary字段的字节数组,那么是 - 将数组内容作为参数值传递给SQL,它会正常工作。(具体你如何做到这一点取决于你的编码语言)
因为你必须创建这样的查询: 假设你有ArrayList arrList有5个employeename所以你可以创建像这样的查询 string strQuery =Insert Into YourTableName(YourColumnName)values(; for(int i = 0; i< arrlist.count; i ++)> { strQuery + = arrList [i]; if(i< arrlist.count-1)> strQuery + =,; } 现在使用此查询,以便您可以在单个插入语句中插入多个值。
Is it possible to insert any array directly to table using Insert statement If yes then let me know... I don''t want to create any function ... i just want to use simple sql query...
解决方案 You could insert all the elements of a delimiter limited string. However, I don''t think that would be of much help. It would be best to insert the elements of the array one by one into a table.No, not as an array of values intended for different rows - SQL doesn''t have any concept of arrays, so it won''t understand them. It is possible (though a PITA to do this via a string made up of comma delimited values, but that is best done as a stored procedure, rather than by an INSERT statement. If it is an array of bytes that you want into a varBinary field on the other hand, then yes - pass the array content to SQL as a parameter value and it will work fine. (Exactly how you do that depends on your coding language)for that you have to create query like that: assume you have ArrayList arrList having 5 employeename so you can create query like string strQuery = "Insert Into YourTableName (YourColumnName) values ("; for(int i=0; i<arrlist.count;i++)> { strQuery += arrList[i]; if(i<arrlist.count-1)> strQuery += ","; } now use this query so that you can insert multiple value in single insert statement.更多推荐
将数组插入sql
发布评论