Nested loop is a easy way of combining data from two row sources.it takes all the rows from outer loop and for each of them it looks up row matching
the join condition from other inner row source.
Write a pl sql program to calculate the yearly bonus that the company gives to its employees.
The company has some criteria is as follows:-
1. If a department_id is 80 then no bonus.
2. if an employee receives >20000 then he/she receives 0.02% bonus,
>15000 then he/she receives 0.03% bonus,
>10000 then he/she receives 0.04% bonus.
Display calculated bonus for an each employee using Nested Loop.
Example:-
DECLARE
  V_DEPT  EMPLOYEES.DEPARTMENT_ID%TYPE;
  lname  EMPLOYEES.LAST_NAME%TYPE;
  V_SAL   EMPLOYEES.SALARY%TYPE;
  V_BONUS V_SAL%TYPE;
BEGIN
  SELECT LAST_NAME,SALARY,DEPARTMENT_ID
  INTO   lname,V_SAL,V_DEPT
  FROM   EMPLOYEES
  WHERE  EMPLOYEE_ID=&EMPNO;
  IF V_DEPT=80 THEN
     V_BONUS :=0;
  ELSE
     IF V_SAL   >= 20000 THEN
        V_BONUS := V_SAL*.2;
     ELSIF V_SAL>=15000 THEN
        V_BONUS := V_SAL*.3;
     ELSIF V_SAL>= 10000 THEN
        V_BONUS := V_SAL *.4;
     ELSE
        V_BONUS := V_SAL*.5;
     END IF;
  END IF;
  DBMS_OUTPUT.PUT_LINE('BONUS OF '||lname||' IS '||V_BONUS);
END;
/
Example 2 :-
BEGINFOR i IN 1..2 LOOP
FOR j IN 1..4 LOOP
DBMS_OUTPUT.PUT_LINE('Outer Loop counter is ' ||
i ||
' Inner Loop counter is ' || j);
END LOOP;
END LOOP;
END;
/
Output:-
Outer Loop counter is 1 Inner Loop counter is 1
Outer Loop counter is 1 Inner Loop counter is 2
Outer Loop counter is 1 Inner Loop counter is 3
Outer Loop counter is 1 Inner Loop counter is 4
Outer Loop counter is 2 Inner Loop counter is 1
Outer Loop counter is 2 Inner Loop counter is 2
Outer Loop counter is 2 Inner Loop counter is 3
Outer Loop counter is 2 Inner Loop counter is 4
 
 
 
 
    
0 comments:
Post a Comment
Thank you for your comments we will get back to soon