Sunday, 14 February 2016

Write a PL/SQL block that will take an input in the form of department number. Increase the salaries of the employees working in the department by 5.5%. If the increment updates the total salary of that department by 255 take back the increment else give the increment permanently.

Write a PL/SQL block that will take an input in the form of department number. 
Increase the salaries of the employees working in the department by 5.5%.If the increment updates the total salary of that department by 255 take back the increment else give the increment permanently.

DECLARE
 dno emp.deptno%type;
 tot emp.sal%type;
 salary emp.sal%TYPE;
 incr emp.sal%TYPE;
BEGIN
 tot:=0;
 SAVEPOINT s1;
 FOR data IN (SELECT EMPNO,DEPTNO,SAL FROM EMP WHERE DEPTNO=&dno)
 LOOP
  incr:=(data.SAL*5.5)/100;
  salary:=data.SAL+incr;
  tot:=tot+incr;
  UPDATE EMP SET SAL=salary WHERE EMPNO=data.EMPNO;
 END LOOP;
 IF tot>=255 THEN
  ROLLBACK TO s1;
  DBMS_OUTPUT.PUT_LINE('Increment Exceed by 255. so,Increment not given permanently');
 ELSE
  COMMIT;
  DBMS_OUTPUT.PUT_LINE('Increment is given permanently.');
 END IF;
END;
/

No comments:

Post a Comment