TP4.sql
create or replace procedure ajout_inter(numi Interventions.numIntervention %type,numv INTERVENTIONS.NUMVEHICULE%type,
                            t Interventions.typeIntervention%type ,dd Interventions.dateDebinterv%type ,
                            df Interventions.dateFininterv%type ,cout Interventions.coutInterv%type)
AS
 cursor cr1 is select *
                from INTERVENTIONS I
                where numi=I.NUMINTERVENTION;
 cursor cr2 is select *
                from VEHICULE
                WHERE NUMVEHICULE=numv;
 c1 cr1%rowtype;
 c2 cr2%rowtype;
 i INTEGER ;
 j INTEGER ;
begin
  i:=0;j:=0;
  FOR c1 in cr1 loop i:= i+1;
  end loop ;
  if(i=0)then
    for c2 in cr2 loop j := j+1;
    end loop;
    if(j=1)then
        insert into INTERVENTIONS values(numi,numv,t,dd,df,cout);
        dbms_output.put_line('Intervention ajouté ! ');
    else
        dbms_output.put_line('ERREUR : violation de la clé étrangère');
    end if;
  else
        dbms_output.put_line('ERREUR : violation de la clé primaire');
  end if ;
end ;
/

execute ajout_inter(1,3,'réparation',to_date('2006/02/25 09:00:00','YYYY-MM-DD HH24:MI:SS' ),
                    to_date('2006/02/26 12:00:00','YYYY-MM-DD HH24:MI:SS'),30000);
execute ajout_inter(1,30,'réparation',to_date('2006/02/25 09:00:00','YYYY-MM-DD HH24:MI:SS' ),
                     to_date('2006/02/26 12:00:00','YYYY-MM-DD HH24:MI:SS'),30000);
execute ajout_inter(13,11,'réparation',to_date('2006/02/25 09:00:00','YYYY-MM-DD HH24:MI:SS' ),
                    to_date('2006/02/26 12:00:00','YYYY-MM-DD HH24:MI:SS'),30000);