Home

You are most welcome to share your knowledge with me, send your comments about this training.

SQL QUERIES

Sunday, 4 January 2015

Nested Loop



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;
/

No comments:

Post a Comment