2017-03-15 52 views
0

我必須寫一個過程,可以在條件下添加一行到一個表中:noli,noconotr是其他表中的關鍵字,所以我必須確保它們已經存在。所以我寫這個解決方案。過程編譯正確,但當我嘗試它時,它給我錯誤對象無效。oracle錯誤過程pl-sql

create or replace procedure insertAffectation 
    (noli2 affectation.noli%type 
    , date_voy2 affectation.date_voy%type 
    , noco2 affectation.noco%type 
    , notr2 affectation%type) 
is 
    v_noli liaison.noli%type; 
    v_date affectation.date_voy%type; 
    v_noco conducteur.noco%type; 
    v_notr train.notr%type; 

begin 

    begin 
     select noli into v_noli from liaison where noli=noli2 ; 
    exception 
     when NO_DATA_FOUND then raise_application_error('-20000','noli does not exist'); 
    end; 

    begin 
     select noco into v_noco from conducteur where noco=noco2; 
    exception 
     when NO_DATA_FOUND then raise_application_error('-20004', ' noco does not exist'); 
    end; 

    begin 
     select notr from train where notr=notr2; 
    exception 
     when NO_DATA_FOUND then raise_application_error('-20001', 'notr does not exist'); 
    end; 

    select embauche into var_date from conducteur where noco=noco2; 

    insert into affectation values(notr2,date_voy2,null,noco2,notr2); 

end insertAffectation; 

和錯誤輸出是:

execute insertAffectation('111254',TO_DATE('01/07/02','DD/MM/YY'),'5555','6666') 
Error report - 
ORA-06550: line 1, column 7: 
PLS-00905: object SYSTEM.INSERTAFFECTATION is invalid 
ORA-06550: line 1, column 7: 
PL/SQL: Statement ignored 
06550. 00000 - "line %s, column %s:\n%s" 
*Cause: Usually a PL/SQL compilation error. 
+0

您可以顯示情感的表格定義,特別是針對所使用的3%類型。 'emotionation.noli%類型, affectation.date_voy%類型, affectation.noco%type,'和什麼是作爲參數%類型參數我沒有看到列。 – xQbert

+0

我錯過了它的affectation.notr%type –

+0

表影響:noli(char(6)),date_voy(DATE),nbpass(數字(3)可以爲null),noco(char(4))notr(char(4 )) –

回答

0

的選項,以解決此Oracle錯誤是:

select embauche into **var_date** from conducteur where noco=noco2; 

但你不聲明var_date,你聲明v_date。改變它,ORA可能已經解決。