Write a PL/SQL block that will update the salaries of the employees working with SCOTT.
If more than FOUR employees salaries are affected by the increment take back the increment,
else give the increment permanently.
DECLARE
ENM EMP.ENAME%TYPE;
TOT EMP.SAL%TYPE;
CNT NUMBER(3);
BEGIN
TOT:=0;
CNT:=0;
SAVEPOINT A;
FOR I IN (SELECT EMPNO,ENAME,SAL FROM EMP WHERE DEPTNO=(SELECT DEPTNO FROM EMP WHERE ENAME='SCOTT'))
LOOP
TOT:=SAL+1000;
UPDATE EMP SET SAL=TOT WHERE EMPNO=I.EMPNO;
CNT:=CNT+1;
END LOOP;
END LOOP;
IF CNT>4 THEN
ROLLBACK TO A;
DBMS_OUTPUT.PUT_LINE('ROLLBACK THE UPDATION.');
ELSE
COMMIT;
DBMS_OUTPUT.PUT_LINE('COMMITED THE UPDATION.');
END IF;
END;
/
If more than FOUR employees salaries are affected by the increment take back the increment,
else give the increment permanently.
DECLARE
ENM EMP.ENAME%TYPE;
TOT EMP.SAL%TYPE;
CNT NUMBER(3);
BEGIN
TOT:=0;
CNT:=0;
SAVEPOINT A;
FOR I IN (SELECT EMPNO,ENAME,SAL FROM EMP WHERE DEPTNO=(SELECT DEPTNO FROM EMP WHERE ENAME='SCOTT'))
LOOP
TOT:=SAL+1000;
UPDATE EMP SET SAL=TOT WHERE EMPNO=I.EMPNO;
CNT:=CNT+1;
END LOOP;
END LOOP;
IF CNT>4 THEN
ROLLBACK TO A;
DBMS_OUTPUT.PUT_LINE('ROLLBACK THE UPDATION.');
ELSE
COMMIT;
DBMS_OUTPUT.PUT_LINE('COMMITED THE UPDATION.');
END IF;
END;
/
No comments:
Post a Comment