程序调用变坏 - 语句被忽略

时间:2015-04-01 11:54:34

标签: oracle stored-procedures

我有以下过程在表中插入用户:

CREATE OR REPLACE PROCEDURE ELR_ADD_USER
                  (I_NAME          IN VARCHAR2,
                   I_MORADA        IN VARCHAR2,
                   I_BIRTHDATE     IN DATE,
                   I_COUNTRY       IN VARCHAR2,
                   O_ID            OUT NUMBER,
                   O_ERROR_MSG     OUT VARCHAR2)
IS
 ERROR_NULL           EXCEPTION;
BEGIN

IF I_NAME IS NULL OR
   I_MORADA IS NULL OR
   I_BIRTHDATE IS NULL OR
   I_COUNTRY IS NULL THEN

       RAISE ERROR_NULL;
END IF;

   O_ID := ELR_seq_USER_ID.nextval;

IF O_ID IS NULL
  RAISE ERROR_NULL;
END IF;

  INSERT INTO ELR_USERS
  VALUES (O_ID, I_NOME, I_MORADA, I_BIRTHDATE, I_COUNTRY);

EXCEPTION 
   WHEN ERROR_NULL THEN
     O_ERROR_MSG := 'NULL FIELDS';
   WHEN OTHERS THEN
     O_ERROR_MSG := 'UNEXPECTED ERROR: '|| sqlerrm;

END;
/

我认为程序及其语法是正确的。但是,当我试图用它来调用它时:

DECLARE
     P_NAME         VARCHAR2(50);
     P_MORADA       VARCHAR2(50);
     P_BIRTHDATE    DATE;
     P_COUNTRY      VARCHAR2(20);
     P_ID           NUMBER(20);
     P_ERROR_MSG    VARCHAR2(4000);
BEGIN

ELR_ADD_USER('ED WARNER','CENAS Street',SYSDATE,
                      'China', P_ID, P_ERROR_MSG);

IF P_ERROR_MSG IS NOT NULL THEN
  DBMS_OUTPUT.PUT_LINE('ERROR: '||P_ERROR_MSG);
END IF;

END;
/

我收到以下消息:

enter image description here

调用或程序本身有问题吗?

1 个答案:

答案 0 :(得分:0)

ORA-06550后跟PLS-00905显然是编译错误。该过程处于 INVALID 状态。

重新编译程序,并使用显示错误获取完整的错误详细信息。

SHOW ERROR PROCEDURE RMS_MM.ELR_ADD_USER或只是SHOW ERRORS

对于example

SQL> CREATE OR REPLACE PROCEDURE TestProc
  2  AS
  3    vnum number;
  4  BEGIN
  5    vnum := vAnotherNum;
  6  END;
  7  /

Warning: Procedure created with compilation errors.

SQL> execute TestProc();
BEGIN TestProc(); END;

*
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00905: object EXAMPLE.TESTPROC is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

SQL> show error procedure TestProc;
Errors for PROCEDURE TESTPROC:

LINE/COL ERROR
-------- -----------------------------------------------------------------
5/1  PL/SQL: Statement ignored
5/9  PLS-00201: identifier 'VANOTHERNUM' must be declared