DB2存储过程参数“在使用它的上下文中无效”

时间:2014-06-18 15:40:22

标签: sql db2

我正在尝试创建以下存储过程:

-- <ScriptOptions statementSeparator="@"/>
-- <ScriptOptions errors="off" platform390="off"/>
@
DROP SPECIFIC PROCEDURE DEPCLH.GetTransactionSummaryByDateRange@

CREATE PROCEDURE  DEPCLH.GetTransactionSummaryByDateRange (in p_DCHDSB_ID INTEGER,in p_StartDate varchar(50),in p_EndDate varchar(50)) 
SPECIFIC  DEPCLH.GetTransactionSummaryByDateRange
LANGUAGE SQL
RESULT SET 1@

BEGIN

DECLARE C_OUTPUT CURSOR WITH RETURN FOR
SELECT
sub.DCHDSB_ID AS FACILITYID,
sub.DCHDSB_CODE AS FACILITYCODE,
sub.NAME AS FACILITYNAME,
SUM(dep.AMOUNT) "TOTALAMOUNT",
COUNT(*) "TRANSACTIONCOUNT"
FROM DEPCLH.DEPOSIT_SUBSCRIBER sub
INNER JOIN DEPCLH.DEPOSIT dep ON dep.DCHDSB_ID=sub.DCHDSB_ID
WHERE sub.DCHDSB_ID=p_DCHDSB_ID AND dep.CREATED_TS BETWEEN p_StartDate AND p_EndDate
GROUP BY sub.DCHDSB_ID,sub.DCHDSB_CODE,sub.NAME
FOR READ ONLY;

OPEN C_OUTPUT;

END 
@

GRANT EXECUTE ON SPECIFIC PROCEDURE  DEPCLH.GetTransactionSummaryByDateRange TO PUBLIC
@

COMMIT
@

我收到以下错误:

  

DB21034E该命令作为SQL语句处理,因为它是   不是有效的命令行处理器命令。在SQL处理期间   返回:SQL0206N“P_DCHDSB_ID”在它所在的上下文中无效   用来。 LINE NUMBER = 3。 SQLSTATE = 42703

1 个答案:

答案 0 :(得分:0)

在代码中找到了Typo。谢谢你的好眼!

-- <ScriptOptions statementSeparator="@"/>
    -- <ScriptOptions errors="off" platform390="off"/>
    @
    DROP SPECIFIC PROCEDURE DEPCLH.GetTransactionSummaryByDateRange@

    CREATE PROCEDURE  DEPCLH.GetTransactionSummaryByDateRange (in p_DCHDSB_ID INTEGER,in p_StartDate varchar(50),in p_EndDate varchar(50)) 
    SPECIFIC  DEPCLH.GetTransactionSummaryByDateRange
    LANGUAGE SQL
    RESULT SET 1

    BEGIN

    DECLARE C_OUTPUT CURSOR WITH RETURN FOR
    SELECT
    sub.DCHDSB_ID AS FACILITYID,
    sub.DCHDSB_CODE AS FACILITYCODE,
    sub.NAME AS FACILITYNAME,
    SUM(dep.AMOUNT) "TOTALAMOUNT",
    COUNT(*) "TRANSACTIONCOUNT"
    FROM DEPCLH.DEPOSIT_SUBSCRIBER sub
    INNER JOIN DEPCLH.DEPOSIT dep ON dep.DCHDSB_ID=sub.DCHDSB_ID
    WHERE sub.DCHDSB_ID=p_DCHDSB_ID AND dep.CREATED_TS BETWEEN p_StartDate AND p_EndDate
    GROUP BY sub.DCHDSB_ID,sub.DCHDSB_CODE,sub.NAME
    FOR READ ONLY;

    OPEN C_OUTPUT;

    END 
    @

    GRANT EXECUTE ON SPECIFIC PROCEDURE  DEPCLH.GetTransactionSummaryByDateRange TO PUBLIC
    @

    COMMIT
    @