drop table tresultat purge;
create table tresultat(ligne varchar2(200));

variable vnumCreneau char(2)
prompt num Creneau?
accept vnumCreneau
variable vhdebut number
prompt heure debut?
accept vhdebut

declare
dnumCreneau char(2):='&vnumCreneau';
dhdebut number:=&vhdebut; 

dmessage varchar2(200);
probleme exception;
dcpt number;

begin	
	dmessage:='ERREUR: num creneau déjà attribué';
	select count(*) into dcpt
		from creneau
		where numCreneau=dnumCreneua;
	if dcpt=1
	then insert into tresultat values (dmessage);
	else dmessage:='Le debut doit etre en 10h et 17h';
		if (dvhdebut <9) or (dvhdebut >17) 
		then  raise probleme;
		else dmessage:='le creneau existe';
			select count(*) into dcpt
	                from creneau 
			where heureDebut=dhdebut;
			id dcpt=0 then raise probleme;
			else 
			insert into reservation values(dnumCreneau,dvhdebut);
			commit;
			insert into tresultat values ('Le creneua a été enregistrée :');
			end if;
		end if;
	end if;
	exception
	when probleme then insert into tresultat values (dmessage);
end;
.
/
select * from tresultat;
