Sunday, 14 February 2016

Write a PL/SQL block that will take an input in the form of department number. Decrease the salaries of the employees working in that department by 0.75%. If at least a record is updated keep the change permanent else print appropriate message and terminate the block.

Write a PL/SQL block that will take an input in the form of department number. 
Decrease the salaries of the employees working in that department by 0.75%.
 If at least a record is updated keep the change permanent else print appropriate message and terminate the block.

DECLARE
 DNO EMP.DEPTNO%TYPE;
 SALARY EMP.SAL%TYPE;
 DECR EMP.SAL%TYPE;
BEGIN
 SAVEPOINT S1;
 FOR DATA IN (SELECT EMPNO,DEPTNO,SAL FROM EMP WHERE DEPTNO=&DNO)
 LOOP
  DECR:=(DATA.SAL*0.75)/100;
  SALARY:=DATA.SAL-DECR;
  UPDATE EMP SET SAL=SALARY WHERE EMPNO=DATA.EMPNO;
 END LOOP;
 IF SQL%ROWCOUNT>=1 THEN
  COMMIT;
  DBMS_OUTPUT.PUT_LINE('One or More record(s) Updated. ');
 ELSE
  ROLLBACK TO S1;
  DBMS_OUTPUT.PUT_LINE('ROLLBACK THE UPDATION.');
 END IF;
END;
/

No comments:

Post a Comment