简体   繁体   English

DB2 存储过程,输出参数始终为 NULL

[英]DB2 stored proc with Out param always NULL

This is DB2 on the IBM I.这是 IBM I 上的 DB2。

I use Run SQL Scripts to test my SP.我使用 Run SQL 脚本来测试我的 SP。 在此处输入图像描述

I even tried to initialize the out parameter as follows and got the same result...我什至尝试如下初始化 out 参数并得到相同的结果......

CALL SGDEDMGT.USPGETBLAHIDFROMBLAHNUM(
  BLAHNO => 'xx#########00000####',  
  /* IN  CHARACTER(20)    */
  BLAHID => '0'   /* OUT INTEGER          */
);

This is the result I get back...这是我回来的结果...

 [ 09/09/2022, 03:45:30 PM ]  Run All...   
  CALL SGDEDMGT.USPGETBLAHIDFROMBLAHNUM( BLAHNO =>                       
  'xx#########00000####',  BLAHID => '0'  )   
  Return Code = 0 
  Output Parameter #2 (BLAHID) = <NULL>   
  Statement ran successfully   (141 ms)

I even tried the CALL with the simplest format, as follows and still receive the same result...我什至用最简单的格式尝试了 CALL,如下所示,仍然收到相同的结果......

CALL SGDEDMGT.USPGETBLAHIDFROMBLAHNUM(
  'xx#########00000####',?);

I just don't understand why I'm getting null for BLAHID.我只是不明白为什么我要为 BLAHID 购买 null。

Here is my stored proc.这是我的存储过程。

CREATE PROCEDURE USPGETBLAHIDFROMBLAHNUM (
    IN BLAHNO CHAR(20),
    OUT BLAHID INTEGER 
    )   
    LANGUAGE SQL
P1 : BEGIN
    DECLARE TMPP INTEGER;
    SET TMPP = (
    SELECT BLAHID
        FROM SGDEDMGT.BLAHS
        WHERE "BlahNumber" = BLAHNO ) ;
    SET BLAHID = TMPP;   
END P1

Btw, in case anyone is wondering, I sanity checked by doing a simple SELECT WHERE just to be sure the test data I'm filtering for is actually there as a returnable value:)顺便说一句,如果有人想知道,我通过做一个简单的 SELECT 来检查我的理智,只是为了确保我过滤的测试数据实际上是一个可返回的值:)

In Run SQL Scripts, you simply pass a parameter marker, ?在运行 SQL 脚本中,您只需传递参数标记, ? , into the call statement for the output parm.. , 进入 output 参数的调用语句..

CALL SGDEDMGT.USPGETBLAHIDFROMBLAHNUM(
  BLAHNO => 'xx#########00000####',  
  /* IN  CHARACTER(20)    */
  BLAHID => ?   /* OUT INTEGER          */
);

--with positional parms
CALL SGDEDMGT.USPGETBLAHIDFROMBLAHNUM('xx#########00000####', ?);

I found my issue.我发现了我的问题。 My fault for not really paying attention.没有真正注意是我的错。 In Line 9 of my Create Procedure example, "SELECT BLAHID" (Note, it's not the real column name and I apologize for being cryptic), the issue itself was BLAHID.在我的创建过程示例的第 9 行中,“SELECT BLAHID”(注意,它不是真正的列名,我为含糊而道歉),问题本身就是 BLAHID。 It should've been BlahId and because the real column name is longer than 6 characters, it should be enclosed in double quotes like "BlahId".它应该是 BlahId,因为实际的列名超过 6 个字符,所以应该用双引号括起来,如“BlahId”。 Why the RUN SQL SCRIPT tool nor post compilation revealed any error about the column name BLAHID not existing is a serious wonder which gave me the false sense of being accurate and thus, running around chasing my own tail.为什么 RUN SQL SCRIPT 工具或编译后显示有关列名 BLAHID 不存在的任何错误是一个严重的奇迹,这给了我准确的错觉,因此,四处奔波追逐自己的尾巴。 Thanks to everyone who spent some time in helping me try to figure out the problem.感谢所有花时间帮助我解决问题的人。 Much appreciated!非常感激!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM