The following is the example using IF_Then statement in an oracle
Note:- Once a condition is found is true,then if-Then-statement will execute the corresponding code and not evaluate the conditions any further.
SQL> DECLARE
2 V_NAME EMPLOYEES.LAST_NAME%TYPE;
3 V_SAL EMPLOYEES.SALARY%TYPE;
4 V_BONUS V_SAL%TYPE;
5 BEGIN
6 SELECT LAST_NAME,SALARY
7 INTO V_NAME,V_SAL
8 FROM EMPLOYEES
9 WHERE EMPLOYEE_ID=&EMPNO;
10
11 IF V_SAL >= 20000 THEN
12 V_BONUS := V_SAL*.2;
13 ELSIF V_SAL>=15000 THEN
14 V_BONUS := V_SAL*.3;
15 ELSIF V_SAL>= 10000 THEN
16 V_BONUS := V_SAL *.4;
17 ELSE
18 V_BONUS := V_SAL*.5;
19 END IF;
20
21 DBMS_OUTPUT.PUT_LINE('BONUS OF '||V_NAME||' IS '||V_BONUS);
22 END;
23 /
Enter value for empno: 200
old 9: WHERE EMPLOYEE_ID=&EMPNO;
new 9: WHERE EMPLOYEE_ID=200;
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> /
Enter value for empno: 200
old 9: WHERE EMPLOYEE_ID=&EMPNO;
new 9: WHERE EMPLOYEE_ID=200;
BONUS OF Whalen IS 2200
PL/SQL procedure successfully completed.
0 comments:
Post a Comment