2

我有这个过程,它只是根据名为AppID. AppNbr此过程从基于该行列调用的另一列中获取一个值AppID。该过程TOO_MANY_ROWS在尝试SELECT一行时失败并出现异常。这是 PL/SQL:

DECLARE
    lvnApplNbr NUMBER;

    PROCEDURE deleteAppl(applId IN VARCHAR2) IS
    BEGIN
        BEGIN
            SELECT ApplNbr -- Exception thrown here
            INTO lvnApplNbr
            FROM Appl
            WHERE ApplID = applId;
        EXCEPTION
            WHEN TOO_MANY_ROWS THEN
                DBMS_OUTPUT.PUT_LINE(SQLERRM);
        END;
        -- ... Delete it after some logic
    END; -- End Procedure
BEGIN
    ...
    deleteAppl('571E00BA-70E6-4523-BEAC-4568C3DD1A7D');
    ...
END;

sTOO_MANY_ROWS时抛出异常。SELECT INTO我不知道它为什么会抛出那个错误,因为如果我只是查询这个:

SELECT ApplNbr FROM Appl WHERE ApplId = '571E00BA-70E6-4523-BEAC-4568C3DD1A7D';

只有一排会返回正确的ApplId.

到底是怎么回事?

4

1 回答 1

5

只需为相关表 ( ) 使用别名Appl

   PROCEDURE deleteAppl(applId IN VARCHAR2) IS
   .....
   .....
   SELECT ApplNbr 
    INTO lvnApplNbr
    FROM Appl a
    WHERE a.ApplID = applId;
   ......

或将参数名称 ( applId) 更改为其他名称,例如i_applId

   PROCEDURE deleteAppl(i_applId IN VARCHAR2) IS
   .....
   .....
   SELECT ApplNbr 
    INTO lvnApplNbr
    FROM Appl
    WHERE ApplID = i_applId;
   ......

parameter's name因为在您的情况下,如果您的和column name相同,则可以感知到多个匹配。

于 2018-08-21T21:06:32.650 回答