1

我有一个非常简单的存储过程:

ALTER PROCEDURE SP_BALANCE_USD
(
  PER SMALLINT
)
RETURNS
(
  ACCOUNT_NUMBER CHAR(21),
  AMOUNT NUMERIC(15, 4)
)
AS
BEGIN
    SELECT
        L.ACCOUNT_NUMBER, SUM(-(CURRROUND(L.DEBIT,2) - CURRROUND(L.CREDIT,2)))
    FROM
        LEDGER L
    WHERE
        L.LEDGER_ACCOUNT = '31621' AND L.PERIOD = :PER
    GROUP BY
        L.ACCOUNT_NUMBER
    INTO
        ACCOUNT_NUMBER, AMOUNT
END;

我收到一个错误:

代币未知第 22 行第 1 列。

第 22 行第 1 列是指代码的最后一行。

在某处我犯了一个非常简单的语法错误,由于某种原因我无法追踪它。任何帮助将不胜感激。

4

1 回答 1

2

令牌未知错误总是在错误消息中包含未知令牌,在这种情况下,未知令牌是END

Engine Code    : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -104
Token unknown - line 23, column 1
END

在存储过程中,每条语句都必须以分号结尾。

更正的程序是:

ALTER PROCEDURE SP_BALANCE_USD
(
  PER SMALLINT
)
RETURNS
(
  ACCOUNT_NUMBER CHAR(21),
  AMOUNT NUMERIC(15, 4)
)
AS
BEGIN
    SELECT
        L.ACCOUNT_NUMBER, SUM(-(CURRROUND(L.DEBIT,2) - CURRROUND(L.CREDIT,2)))
    FROM
        LEDGER L
    WHERE
        L.LEDGER_ACCOUNT = '31621' AND L.PERIOD = :PER
    GROUP BY
        L.ACCOUNT_NUMBER
    INTO
        ACCOUNT_NUMBER, AMOUNT;
END

注意语句最后一行的;after 。AMOUNTSELECT

于 2019-11-24T11:05:55.227 回答