1

我正在尝试创建一个将单行插入表中的存储过程。传递给此过程的参数将被插入到表中。

CREATE OR REPLACE PROCEDURE proc_sal(
    ename IN VARCHAR2, basic IN NUMBER,
    hra IN NUMBER, doj IN VARCHAR2, gender IN VARCHAR2,
    deptcode IN VARCHAR2, err OUT NUMBER, emsg OUT VARCHAR2)
IS
    eid VARCHAR2(30);
    no NUMBER;
BEGIN
   SELECT salseq.NEXTVAL INTO no FROM dual;

   eid := CONCAT(deptcode,LPAD(no,5,'0'));

   INSERT INTO salary_det
   VALUES('eid', 'ename', basic, hra, 'doj', 'gender');

   err := 1;
EXCEPTION
  WHEN OTHERS THEN
    err := SQLCODE;
    emsg := SQLERRM;
    DBMS_OUTPUT.PUT_LINE(emsg);
END;

通过匿名块调用此过程:

DECLARE
   errcd NUMBER;
   errmsg VARCHAR2(200);
BEGIN
   proc_sal('&empname',&basic, &hra,'&date','&gender','&deptcode', errcd, errmsg);
   DBMS_OUTPUT.PUT_LINE(errcd||' '||errmsg);
END;

以下是我收到的输出:

   Enter value for empname: Mohan
   Enter value for basic: 56000
   Enter value for hra: 560
   Enter value for date: 12-JUL-12
   Enter value for gender: M
   Enter value for deptcode: EA
   old   5:  proc_sal('&empname',&basic, &hra, '&date','&gender','&deptcode', errcd,  errmsg);
   new   5:  proc_sal('Mohan',56000, 560, '12-JUL-12','M','EA', errcd, errmsg);

   ORA-01858: a non-numeric character was found where a numeric was expected       
   -1858 ORA-01858: a non-numeric character was found where a numeric was expected 

   PL/SQL procedure successfully completed.

尝试单独运行时,其他一切都在程序中运行。在 sql 中尝试时会发生插入。没有列名或值不匹配,仍然无法找出问题所在。

4

1 回答 1

1

问题是您将变量的名称括在撇号中,试试这个:

CREATE OR REPLACE PROCEDURE proc_sal(
    ename IN VARCHAR2, basic IN NUMBER,
    hra IN NUMBER, doj IN VARCHAR2, gender IN VARCHAR2,
    deptcode IN VARCHAR2, err OUT NUMBER, emsg OUT VARCHAR2)
IS
  eid VARCHAR2(30);
  no NUMBER;
BEGIN
  SELECT salseq.NEXTVAL INTO no FROM dual;

  eid := CONCAT(deptcode,LPAD(no,5,'0'));

  INSERT INTO salary_det
    VALUES(eid, ename, basic, hra, doj, gender);

  err := 1;
EXCEPTION
  WHEN OTHERS THEN
    err := SQLCODE;
    emsg := SQLERRM;
    DBMS_OUTPUT.PUT_LINE(emsg);
END;
于 2013-11-01T19:26:38.560 回答