PROGRAM THAT FETCHES THE DEPT NAME AND LOCATION OF A GIVEN DEPTNO AND RAISES THE USER DEFINED EXCEPTION IF DEPTNO DOES NOT EXIST IN ORACLE?
SQL>
DECLARE
2
LOCATION DEPT.LOC%TYPE;
3
NAME DEPT.DNAME%TYPE;
4 DNO
DEPT.DEPTNO%TYPE;
5
DEPTNO_ERR EXCEPTION;
6
BEGIN
7
DNO:=&DNO;
8 IF
DNO NOT IN (10, 20, 30, 40) THEN
9
RAISE DEPTNO_ERR;
10 END
IF;
11
SELECT DNAME, LOC INTO NAME, LOCATION FROM
DEPT WHERE DEPTNO=DNO;
12
DBMS_OUTPUT.PUT_LINE('LOCATION IS '||LOCATION);
13 DBMS_OUTPUT.PUT_LINE('
DEPT NAME IS '||NAME);
14
EXCEPTION
15
WHEN DEPTNO_ERR THEN
16
DBMS_OUTPUT.PUT_LINE('DEPARTMENT NUMBER
DOES NOT EXIST');
17 END;
18 /
Enter
value for dno: 20
old 7:
DNO:=&DNO;
new 7:
DNO:=20;
LOCATION
IS DALLAS
DEPT
NAME IS RESEARCH
PL/SQL
procedure successfully completed.
Comments
Post a Comment