PLS-00330在包体上无效使用类型名称或子类型名称

时间:2016-11-23 23:14:37

标签: oracle plsql oracle-sqldeveloper

我是PL / SQL的新手,我试图创建这个软件包,到目前为止我遇到了很多问题。

create or replace PACKAGE Pkg IS
   TYPE motivos IS TABLE OF VARCHAR2(50) INDEX BY BINARY_INTEGER;
   PROCEDURE Proc(lote IN VARCHAR2, e IN NUMBER, obs IN VARCHAR2, motives IN motivos);
END Pkg;
/
CREATE OR REPLACE PACKAGE BODY Pkg IS
    PROCEDURE Proc(lote IN VARCHAR2, e IN NUMBER, obs IN VARCHAR2, motives IN motivos) AS
    exist NUMBER(2);
    BEGIN
        SELECT count(*) INTO exist
        FROM Lote l
        WHERE l.numero=lote;

        IF exist>0 THEN
            UPDATE Lote SET empleadoDescarte=e, observacionesDescarte=obs, fechaDescarte=sysdate WHERE numero=lote;
      COMMIT;

            FOR motivo IN motivos           
            LOOP    
                Insert into MOTIVO (NROLOTE, MOTIVO) values (lote,motivo);
            END LOOP;           
      COMMIT;

            DBMS_OUTPUT.PUT_LINE('Ok.');
        ELSE
            DBMS_OUTPUT.PUT_LINE('Error.');
        END IF;     
    END;
END Pkg;
/

当我将其作为脚本运行时,它会给我以下错误:

Error(13,4): PL/SQL: Statement ignored
Error(13,18): PLS-00330: invalid use of type name or subtype name

问题在于exist,我还没有通过阅读与此问题相关的其他问题找出原因

1 个答案:

答案 0 :(得分:1)

您在使用变量和类型方面存在一些问题;尝试以这种方式编辑:

CREATE OR REPLACE PACKAGE BODY Pkg IS
    PROCEDURE Proc(
                   lote       IN VARCHAR2,
                   e          IN NUMBER,
                   obs        IN VARCHAR2,
                   motives    IN motivos
                  ) AS
        exist                                   NUMBER(2);
    BEGIN
        SELECT COUNT(*)
          INTO exist
          FROM Lote l
         WHERE l.numero = lote;

        IF exist > 0
        THEN
            UPDATE Lote
               SET empleadoDescarte         = e,
                   observacionesDescarte    = obs,
                   fechaDescarte            = SYSDATE
             WHERE numero = lote;

            COMMIT;

            FOR i IN motives.first .. motives.last
            LOOP
                INSERT INTO MOTIVO(NROLOTE, MOTIVO)
                     VALUES (lote, motives(i));
            END LOOP;

            COMMIT;

            DBMS_OUTPUT.PUT_LINE('Ok.');
        ELSE
            DBMS_OUTPUT.PUT_LINE('Error.');
        END IF;
    END;
END Pkg;
/

此外,更好的命名约定可能有助于轻松查看此类问题;例如,如果您调用IN参数p_XXX和类型ty_XXX,则在代码的每个位置都可以轻松理解什么是参数,类型等等