<legend id='HvoRR'><style id='HvoRR'><dir id='HvoRR'><q id='HvoRR'></q></dir></style></legend>

  • <i id='HvoRR'><tr id='HvoRR'><dt id='HvoRR'><q id='HvoRR'><span id='HvoRR'><b id='HvoRR'><form id='HvoRR'><ins id='HvoRR'></ins><ul id='HvoRR'></ul><sub id='HvoRR'></sub></form><legend id='HvoRR'></legend><bdo id='HvoRR'><pre id='HvoRR'><center id='HvoRR'></center></pre></bdo></b><th id='HvoRR'></th></span></q></dt></tr></i><div id='HvoRR'><tfoot id='HvoRR'></tfoot><dl id='HvoRR'><fieldset id='HvoRR'></fieldset></dl></div>

      <tfoot id='HvoRR'></tfoot>

      <small id='HvoRR'></small><noframes id='HvoRR'>

          <bdo id='HvoRR'></bdo><ul id='HvoRR'></ul>
      1. 从java调用带有表值参数的存储过程

        Call stored procedure with table-valued parameter from java(从java调用带有表值参数的存储过程)
          <bdo id='MWtQG'></bdo><ul id='MWtQG'></ul>

                <legend id='MWtQG'><style id='MWtQG'><dir id='MWtQG'><q id='MWtQG'></q></dir></style></legend>
                  <tbody id='MWtQG'></tbody>
                1. <i id='MWtQG'><tr id='MWtQG'><dt id='MWtQG'><q id='MWtQG'><span id='MWtQG'><b id='MWtQG'><form id='MWtQG'><ins id='MWtQG'></ins><ul id='MWtQG'></ul><sub id='MWtQG'></sub></form><legend id='MWtQG'></legend><bdo id='MWtQG'><pre id='MWtQG'><center id='MWtQG'></center></pre></bdo></b><th id='MWtQG'></th></span></q></dt></tr></i><div id='MWtQG'><tfoot id='MWtQG'></tfoot><dl id='MWtQG'><fieldset id='MWtQG'></fieldset></dl></div>

                  <tfoot id='MWtQG'></tfoot>

                  <small id='MWtQG'></small><noframes id='MWtQG'>

                  本文介绍了从java调用带有表值参数的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我想执行像 SELECT * FROM tbl WHERE col IN (@list) 之类的查询,其中,@list 可以有变量没有值.我正在使用 MS SQL 服务器数据库.当我用谷歌搜索这个问题时,我找到了这个链接

                  In my application I want to execute query like SELECT * FROM tbl WHERE col IN (@list) where,@list can have variable no of values. I am using MS SQL server database. When I google this problem then I found this link

                  http://www.sommarskog.se/arrays-in-sql-2008.html

                  此链接说要使用表值参数.所以我使用 Microsoft SQL Server Management Studio 创建了用户定义的数据类型.

                  This link says to use table-valued parameter. So I created user-defined data type using Microsoft SQL Server Management Studio.

                  CREATE TYPE integer_list_tbltype AS TABLE (n int NOT NULL PRIMARY KEY)

                  然后我写了存储过程

                  CREATE PROCEDURE get_product_names @prodids integer_list_tbltype READONLY AS
                     SELECT p.ProductID, p.ProductName
                     FROM   Northwind.dbo.Products p
                     WHERE  p.ProductID IN (SELECT n FROM @prodids)
                  

                  然后只使用管理工作室我执行了这个程序

                  and then using management studio only I executed this procedure

                  DECLARE @mylist integer_list_tbltype
                  INSERT @mylist(n) VALUES(9),(12),(27),(37)
                  EXEC get_product_names @mylist
                  

                  它给了我正确的输出.但我想知道如何从 java 源代码调用这个存储过程.我知道如何使用常量数量的参数调用简单的存储过程

                  and it is giving me correct output. But I am wondering how to call this stored procedure from java source code. I know how to call simple stored procedure with constant number of argument

                  CallableStatement proc_stmt = null;
                  proc_stmt = con.prepareCall("{call test(?)}");
                  proc_stmt.setString(1,someValue);
                  

                  但是如何在表值参数的情况下调用存储过程?

                  but how to call stored procedure in table-value parameter case?

                  推荐答案

                  搜索了一段时间后,我找到了这个问题的答案.特别是当您使用 IN 子句并且操作数不可变时,您可以使用逗号分隔的值作为IN 子句中的输入.

                  After searching for a while I found answer of this problem.Specially when you use IN clause and no of operands are variable then you can use comma-delimited values as an input in IN clause.

                  以下示例显示了如何使用动态 SQL 检索指定律师类型的所有律师的存储过程.

                  Here's the example how the stored procedure that will retrieve all lawyers of the given lawyer type in the provided ZIP code will look like using dynamic SQL.

                  CREATE PROCEDURE [dbo].[GetLawyers] ( @ZIP CHAR(5), @LawyerTypeIDs VARCHAR(100) )
                  AS
                  
                  DECLARE @SQL     VARCHAR(2000)
                  
                  SET @SQL = 'SELECT * FROM [dbo].[Lawyers]
                              WHERE [ZIP] = ' + @ZIP + ' AND
                                    [LawyerTypeID] IN (' + @LawyerTypeIDs + ')'
                  EXECUTE (@SQL)
                  
                  GO
                  

                  执行存储过程,以逗号分隔值传递用户输入的邮政编码和选定的律师类型:

                  To execute the stored procedure passing the ZIP code entered by the user and the selected lawyer types in a comma separated value:

                  EXECUTE [dbo].[GetLawyers] '12345', '1,4'
                  

                  所以结论是你不需要使用TVP.无论您使用哪种语言[Java,PHP],只需将参数作为逗号分隔的字符串传递给存储过程,它就会完美运行.

                  So conclusion is you do not need to use TVP. Whichever language[Java, PHP] you use just pass parameters as comma-delimited string to stored procedure and it will work perfect.

                  所以在JAVA中你可以调用上面的存储过程:-

                  So in JAVA you can call above stored procedure:-

                  proc_stmt = con.prepareCall("{call GetLawyers(?,?)}");
                  proc_stmt.setString(1,"12345");
                  proc_stmt.setString(2,"'1,4'");
                  

                  这篇关于从java调用带有表值参数的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                    <bdo id='qoDlD'></bdo><ul id='qoDlD'></ul>
                      <legend id='qoDlD'><style id='qoDlD'><dir id='qoDlD'><q id='qoDlD'></q></dir></style></legend>

                        <small id='qoDlD'></small><noframes id='qoDlD'>

                            <tbody id='qoDlD'></tbody>
                          <i id='qoDlD'><tr id='qoDlD'><dt id='qoDlD'><q id='qoDlD'><span id='qoDlD'><b id='qoDlD'><form id='qoDlD'><ins id='qoDlD'></ins><ul id='qoDlD'></ul><sub id='qoDlD'></sub></form><legend id='qoDlD'></legend><bdo id='qoDlD'><pre id='qoDlD'><center id='qoDlD'></center></pre></bdo></b><th id='qoDlD'></th></span></q></dt></tr></i><div id='qoDlD'><tfoot id='qoDlD'></tfoot><dl id='qoDlD'><fieldset id='qoDlD'></fieldset></dl></div>
                          <tfoot id='qoDlD'></tfoot>