Exceptions Oracle

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

set SERVEROUTPUT ON

DECLARE
nom employees.last_name%type;
begin
select last_name into nom from employees where first_name = '&prenom';
DBMS_OUTPUT.PUT_line(nom);
end;

EXCEPTION
when no_data_found then
DBMS_OUTPUT.PUT_line('le prénom saisi néxiste pas' );
when too_many_rows then
DBMS_OUTPUT.PUT_line('plusieurs emlpoyées ont le prénom saisi ' );
when others then
DBMS_OUTPUT.PUT_line('Contactez-nous SVP' );

set SERVEROUTPUT ON
DECLARE
ex_insert exception;
pragma exception_init(ex_insert, -1400);
begin
begin
insert into departments(department_id, department_name) values (1, null);
exception
when ex_insert then
dbms_output.put_line('le prénom ne peut pas être null');
dbms_output.put_line('code de lerreur :'||sqlcode);
dbms_output.put_line('le message de lerreur :' || sqlerrm);
end;

begin
update employees set employee_id='abc' where employee_id = 100;
EXCEPTION
when others then
dbms_output.put_line('id employé doit être numérique');
end;
commit;
end;

set SERVEROUTPUT ON
DECLARE
ex_update exception;

begin
update employees set salary=20000 where employee_id = 1;
if sql%notfound then
raise ex_update;
end if;
commit;
EXCEPTION
when ex_update then
dbms_output.put_line('pas de salarié avec le id = 1');
end;

set SERVEROUTPUT ON
DECLARE

begin
update employees set salary=20000 where employee_id = 1;
if sql%notfound then
RAISE_APPLICATION_ERROR(-20000, 'Modification non efféctué car le id=1 n\éxiste
pas.');
end if;
commit;
end;

dbms_output.put_line('le manager est :' ||nom||'du departement' ||departement);

You might also like