How can I call a DB2 stored procedure with OUT par

2019-04-08 15:41发布

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, ?);

7条回答
SAY GOODBYE
2楼-- · 2019-04-08 16:03

I would think that if there is one in then the call should be:

CALL SomeSProc(12345)

to get a result maybe try:

SELECT * FROM SomeSProc(12345)
查看更多
地球回转人心会变
3楼-- · 2019-04-08 16:06

change statement separator in squirrel > session > session properties > SQL : '#'

BEGIN
    DECLARE inOutParam varchar(200);
    set inOutParam =  'a value';
    STORED_PROC_NAME(outParam);
END;
#
查看更多
forever°为你锁心
4楼-- · 2019-04-08 16:07

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

call SOMESPROC(12345, ?);
查看更多
Evening l夕情丶
5楼-- · 2019-04-08 16:10

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.

BEGIN
    DECLARE outParam INT;
    STORED_PROC_NAME(outParam);
END

If you also need to provide input for the procedure you could do this.

BEGIN
    DECLARE outParam INT;
    STORED_PROC_NAME('input', outParam);
END

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.

查看更多
你好瞎i
6楼-- · 2019-04-08 16:11

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:

wbcall SOMESPROC(12345, ?);

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.

查看更多
三岁会撩人
7楼-- · 2019-04-08 16:13

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...

begin
declare inoutParm numeric(2,0);
call spMyStoredProcedure(
             1234567                                     
           , inoutParm                                           
       );
declare global temporary table session.myTempTbl  
       (MyResult   char(1024) )                                         
with replace ;
insert into session.myTempTbl
  (myResult)
   values(inoutParm) ;  
end
~
select myResult from session.myTempTbl

Mic Keeley as400(db2) SQL Developer

查看更多
登录 后发表回答