Exception Handling in PL/SQL
DECLARE
MEMNAME EMP.ENAME%TYPE;
BEGIN
SELECT ENAME INTO MEMNAME FROM EMPKRIS
WHERE EMPNO = &INPUT_EMPNO;
DBMS_OUTPUT.PUT_LINE(MEMNAME);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No Such Employee');ed
END;
/
DECLARE
N number:=10;
Y number:=0;
i number;
begin
for i in -2..2
loop
y:=i;
begin
N:=10/y;
DBMS_output.put_line('value of N is after division is : ' || N);
Exception
When ZERO_Divide then
DBMS_output.put_line('value of Y is :: ' || Y || ' exception caught');
Y:=100;
N:=10/y;
DBMS_output.put_line('value of N is after division in exception block : ' || N);
end;
end loop;
end;
MEMNAME EMP.ENAME%TYPE;
BEGIN
SELECT ENAME INTO MEMNAME FROM EMPKRIS
WHERE EMPNO = &INPUT_EMPNO;
DBMS_OUTPUT.PUT_LINE(MEMNAME);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No Such Employee');ed
END;
/
DECLARE
N number:=10;
Y number:=0;
i number;
begin
for i in -2..2
loop
y:=i;
begin
N:=10/y;
DBMS_output.put_line('value of N is after division is : ' || N);
Exception
When ZERO_Divide then
DBMS_output.put_line('value of Y is :: ' || Y || ' exception caught');
Y:=100;
N:=10/y;
DBMS_output.put_line('value of N is after division in exception block : ' || N);
end;
end loop;
end;