FUNCTION TO DISPLAY THE SALARY OF EMPLOYEE WHOSE EMPNO IS GIVEN IN ORACLE?
SQL>
DECLARE
2 ECODE EMP.EMPNO%TYPE;
3 SALARY EMP.SAL%TYPE;
4 FUNCTION CAL_SAL(E NUMBER) RETURN NUMBER AS
5 S EMP.SAL%TYPE;
6 BEGIN
7 SELECT SAL INTO S FROM EMP WHERE
EMPNO=ECODE;
8 RETURN S;
9 EXCEPTION
10 WHEN NO_DATA_FOUND THEN
11 RETURN 0;
12 END CAL_SAL;
13 BEGIN
14 ECODE := &ECODE;
15 SALARY:= CAL_SAL (ECODE);
16 IF SALARY !=0 THEN
17 DBMS_OUTPUT.PUT_LINE('SALARY IS = '||SALARY);
18 ELSE
19 DBMS_OUTPUT.PUT_LINE('EMPLOYEE DOES NOT
EXIST');
20 END IF;
21 END;
22 /
Enter
value for ecode: 7499
old 14: ECODE := &ECODE;
new 14: ECODE := 7499;
SALARY
IS = 2942.05
PL/SQL
procedure successfully completed.
SQL>
START DISPLAY.SQL;
Enter
value for ecode: 7369
old 14: ECODE := &ECODE;
new 14: ECODE := 7369;
SALARY
IS = 1469.5
PL/SQL
procedure successfully completed.
Comments
Post a Comment