在IBM i上的DB2上的存储过程中插入行

时间:2016-08-19 20:39:03

标签: sql stored-procedures insert db2

我正在调用存储过程

call tag_foreign_crossdock_order ( 58379, 90, 95, 29 )  ;

存储过程编码为

CREATE or replace PROCEDURE TAG_FOREIGN_CROSSDOCK_ORDER ( 
    IN ORDERNBR DECIMAL(7, 0) , 
    IN STORENBR DECIMAL(3, 0) , 
    IN FROMWHSENBR DECIMAL(3, 0) , 
    IN TOWHSENBR DECIMAL(3, 0) ) 
    LANGUAGE SQL 
    SPECIFIC TAG_FOREIGN_CROSSDOCK_ORDER 
    DETERMINISTIC 
    MODIFIES SQL DATA 
    CALLED ON NULL INPUT 
    PROGRAM TYPE SUB 
    COMMIT ON RETURN YES 
    SET OPTION  ALWBLK = *ALLREAD , 
    ALWCPYDTA = *OPTIMIZE , 
    COMMIT = *NONE , 
    CLOSQLCSR = *ENDACTGRP , 
    DECRESULT = (31, 31, 00) , 
    DFTRDBCOL = *NONE , 
    DLYPRP = *NO , 
    DYNDFTCOL = *NO , 
    DYNUSRPRF = *USER , 
    SRTSEQ = *HEX   
    INSERT INTO t799.ORDXDKP 
( 
OXORD , 
OXFWHS , 
OXTWHS , 
OXSTR , 
OXSTS , 
OXNEWORD , 
OXINV , 
OXCRTTS , 
OXUPDTS ,
OXdldate
) 

VALUES 
( 
ORDERNBR , 
FROMWHSENBR , 
TOWHSENBR , 
STORENBR , 
0 , 
0 , 
0 , 
NOW ( ) , 
NOW ( ) ,
(SELECT  dsdeldate 
   FROM qs36f.dstophp 
  WHERE dsord# = ORDERNBR
    AND dswhs = FROMWHSENBR
    AND dsstr = STORENBR))  ; 

当我从iNav调用sp时,我得到了 SQL State:23502 供应商代码:-407 消息:[SQL0407]列或变量中不允许空值。

如果我自己运行insert语句,则正确插入记录。

INSERT INTO t799.ORDXDKP (OXORD , OXFWHS , OXTWHS , OXSTR , OXSTS , OXNEWORD , OXINV , OXCRTTS , OXUPDTS, oxdldate ) 
        values ( 58379 , 90 , 95 , 29 , 0 , 0 , 0 , NOW ( ) , NOW ( ), 
       (select  dsdeldate from dstophp where dsord# = 58379 and dswhs = 90 and dsstr = 29)  )  ; 

在存储过程中,我是否可以在子选择中访问传入的变量?这可以解释为什么最后一列为空。

还有其他原因吗?

谢谢,

罗布

0 个答案:

没有答案