2013-11-01 95 views
1

我試圖創建一個存儲過程,將單行插入到表中。傳遞給此過程的參數 將被插入到表中。存儲過程 - PL/SQL - 插入錯誤

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中嘗試插入時發生。沒有不匹配的列名或值,仍然無法弄清楚什麼是錯的。

+0

歡迎SO。表格的定義是什麼? – igr

+1

insert命令試圖在這裏插入字符串值:'VALUES('eid','ename',basic,hra,'doj','gender');' - 'eid','ename','doj'和'gender'是字符串,因爲它們被包含在撇號中。 – krokodilko

回答

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; 
+0

非常感謝。有效。檢查了一切,但忘了引號!!!! – Tao