PL/SQL EXCEPTIONS : WHEN NO_DATA_FOUND
EXAMPLES :
1 DECLARE
2 V_NUMBER NUMBER(4);
3 V_NAME VARCHAR2(20);
4 V_SAL NUMBER(5);
5 BEGIN
6 SELECT EMPNO,ENAME,SAL INTO V_NUMBER,V_NAME,V_SAL FROM EMP WHERE EMPNO = 7839;
7 DBMS_OUTPUT.PUT_LINE(V_NUMBER || V_NAME || V_SAL);
8 EXCEPTION
9 WHEN NO_DATA_FOUND
10 THEN
11 DBMS_OUTPUT.PUT_LINE('NO EMPLOYEE EXISTS IN THIS NAME');
12* END;
SQL> /
7839 KING 5000
PL/SQL procedure successfully completed.
(GIVE WRONG EMPLOYEE NUMBER THEN YOU WILL GET THIS ERROR);
1 DECLARE
2 V_NUMBER NUMBER(4);
3 V_NAME VARCHAR2(20);
4 V_SAL NUMBER(5);
5 BEGIN
6 SELECT EMPNO,ENAME,SAL INTO V_NUMBER,V_NAME,V_SAL FROM EMP WHERE EMPNO = 333;
7 DBMS_OUTPUT.PUT_LINE(V_NUMBER || V_NAME || V_SAL);
8 EXCEPTION
9 WHEN NO_DATA_FOUND
10 THEN
11 DBMS_OUTPUT.PUT_LINE('NO EMPLOYEE EXISTS IN THIS NAME');
12* END;
SQL> /
NO EMPLOYEE EXISTS IN THIS NAME
PL/SQL procedure successfully completed.
TOO_MANY_ROWS EXCEPTIONS
EXAMPLE:
DECLARE
V_NUMBER NUMBER(4);
BEGIN
SELECT EMPNO INTO V_NUMBER FROM EMP E;
DBMS_OUTPUT.PUT_LINE(V_NUMBER);
EXCEPTION
WHEN TOO_MANY_ROWS
THEN
DBMS_OUTPUT.PUT_LINE('THERE ARE TOO MANY ROWS RETRIVING');
END;
/
No comments:
Post a Comment