Created
August 14, 2018 07:44
-
-
Save abrarShariar/0463a659c0000838302f93ae1281f649 to your computer and use it in GitHub Desktop.
plsql lab final
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
DECLARE | |
eno emp.empno%TYPE; | |
ename emp.ename%TYPE; | |
salary emp.salary%TYPE; | |
CURSOR c_emp is | |
SELECT empno,ename,salary FROM emp where rownum < 6 order by salary desc; | |
BEGIN | |
OPEN c_emp; | |
LOOP | |
FETCH c_emp into eno, ename, salary; | |
EXIT WHEN c_emp%notfound; | |
dbms_output.put_line(eno|| ' ' || ename|| ' ' || salary); | |
END LOOP; | |
CLOSE c_emp; | |
END; | |
//2 | |
DECLARE | |
row_num number := :num; | |
total number := 0; | |
salary emp.salary%TYPE; | |
counter number := 0; | |
PROCEDURE total_sal(n IN number) IS | |
CURSOR c_emp is | |
SELECT salary FROM emp; | |
BEGIN | |
OPEN c_emp; | |
LOOP | |
FETCH c_emp into salary; | |
EXIT WHEN counter > n; | |
total := total + salary; | |
counter := counter + 1; | |
END LOOP; | |
CLOSE c_emp; | |
dbms_output.put_line(total); | |
END; | |
BEGIN | |
total_sal(row_num); | |
END; | |
//3 | |
DECLARE | |
AVG_SAL NUMBER; | |
eno emp.empno%TYPE; | |
salary emp.salary%TYPE; | |
CURSOR c_emp is | |
select empno from emp; | |
BEGIN | |
SELECT ROUND(avg(salary)) into AVG_SAL from emp; | |
OPEN c_emp; | |
LOOP | |
FETCH c_emp into eno, salary; | |
IF(salary < AVG_SAL) THEN | |
UPDATE emp SET salary=AVG_SAL WHERE empno=eno; | |
ENDIF; | |
END LOOP; | |
CLOSE c_emp; | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment