如何从 SQuirreL SQL 调用带有 OUT 参数的 DB2 存储过程?
我真的很喜欢 SQuirreL SQL 作为 SQL 查询工具,但我一直无法让它调用我们的 AS/400 DB2 数据库中的存储过程。我总是收到错误“设置或注册的参数值的数量与参数的数量不匹配。”我已经仔细检查了参数的数量,但没有运气。这是我为一个需要一个输入和一个输出的过程尝试过的语法:
call SOMESPROC(12345, ?);
I really like SQuirreL SQL as a SQL query tool, but I've never been able to get it to call stored procedures in our AS/400 DB2 database. I always get the error "The number of parameter values set or registered does not match the number of parameters." I've double-checked the number of params and had no luck. This is the syntax I've tried for a procedure that takes one IN and one OUT:
call SOMESPROC(12345, ?);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
SQuirrel 目前似乎无法在 AS/400 DB2 上执行此操作。
使用开源“SQL Workbench/J”(http://www.sql-workbench.net/) 我能够调用一个过程:
它有自己的用于调用过程“wbcall”的命令。使用 ?对于输出参数。
注意:安装 SQL Workbench/J 时,请确保从 下载正确的 DB2 驱动程序IBM 并在 SQL Workbench/J 中添加驱动程序时添加许可证文件。
It seems that SQuirrel currently is not capable of doing that on AS/400 DB2.
Using the open source "SQL Workbench/J" (http://www.sql-workbench.net/) I was able to call a procedure:
It has its own command for calling a procedure "wbcall". Use ? for out parameters.
Note: While installing SQL Workbench/J make sure to download the right DB2 driver from IBM and also add the licence file while adding the driver inside SQL Workbench/J.
在 Squirrel 中你可以使用这样的东西。您需要确保声明的变量的类型与存储过程中的输出参数的类型匹配。
如果您还需要为该过程提供输入,您可以这样做。
您还需要将语句分隔符更改为
;
以外的内容。否则,它将分解该语句并尝试单独发送每个部分。In Squirrel you can use something like this. You'll want to make sure the type of the declared variable matches the type of your out parameter in the stored procedure.
If you also need to provide input for the procedure you could do this.
You also need to change the statement separator to something other than
;
. Otherwise it will break up the statement and try to send each piece individually.在 DbVisualizer 专业版中,启用 SQL Commander 菜单选项下的“SQL 中的处理参数标记”后,它将允许“?”参数
In the pro version of DbVisualizer, with the "Process Parameter Markers in SQL" under the SQL Commander menu option enabled, it will allow the "?" param
经过反复试验,我在 Squirrel 中看到了结果。
through trial and error, I was able to see the results in Squirrel.
我认为,如果其中有一个,那么调用应该是:
要得到结果,可以尝试:
I would think that if there is one in then the call should be:
to get a result maybe try:
下面是一个经过测试的示例,它使用 db2 存储过程在 Squirrel 3.7 上运行。诀窍是通过过渡存储过程 MY_PROC_TEST 来调用真正的存储过程 PROC_TEST。
松鼠中的更改语句分隔符>会话>会话属性> SQL : @
然后你可以像这样调用这个过程:
CALL MY_PROC_TEST()@
Here is an tested example which works on Squirrel 3.7 with a db2 stored procedure . The trick is to passe with an transitional stored procedure MY_PROC_TEST to call the real stored procedure PROC_TEST.
change statement separator in squirrel > session > session properties > SQL : @
Then you can call the sored procedure like this :
CALL MY_PROC_TEST()@
如果您更改分隔符(如上所述),这将在 Squirrel 中起作用。但是,要查看变量是什么,您需要执行以下操作...
在我的示例中,我将分隔符设置为斜线 (~)。包括在最后一个“end”之后、“select”之前。代码从这里开始...
Mic Keeley
as400(db2) SQL 开发人员
This will work in Squirrel if you change the delimiter (as specified above). However, to see what the variable is, you need to do the following...
In my example, I will set the delimiter to a tildy (~). Include after last "end", before "select". Code begins here...
Mic Keeley
as400(db2) SQL Developer
我能够将上述所有答案拼凑在一起,并得出对我有用的答案。我正在使用 Squirrel SQL 2018 连接到 IBM AS/400 DB2 数据库。我确实必须声明一个语句分隔符,我使用了“#”。
I was able to cobble together some amalgamation of all of the above answers and came up with this which worked for me. I'm using Squirrel SQL 2018 connecting to an IBM AS/400 DB2 database. I did have to declare a statement separator, I used "#".
松鼠中的更改语句分隔符>会话>会话属性> SQL:'#'
change statement separator in squirrel > session > session properties > SQL : '#'