. PROGRAM TO CALCULATE MAXIMUM, MINIMUM AND AVERAGE SALARY DEPT WISE AND DISPLAY THE RESULT USING CURSOR IN ORACLE?



SQL> DECLARE
  2  CURSOR INFO_CURSOR IS
  3  SELECT DEPTNO, MAX (SAL), MIN (SAL), AVG (SAL)
      FROM EMP GROUP BY DEPTNO;
  4  DCODE EMP. DEPTNO % TYPE;
  5  MAXSAL EMP.SAL% TYPE;
  6  MINSAL EMP.SAL% TYPE;
  7  AVGSAL EMP.SAL% TYPE;
  8  BEGIN
  9  OPEN INFO_CURSOR;
 10  LOOP
 11  FETCH INFO_CURSOR INTO DCODE, MAXSAL, MINSAL,
       AVGSAL;
 12  EXIT WHEN INFO_CURSOR%NOTFOUND;
 13  DBMS_OUTPUT.PUT_LINE (DCODE || ' '|| MAXSAL || ' '||
       MINSAL || ' ' || AVGSAL );
 14  END LOOP;
 15  CLOSE INFO_CURSOR;
 16  END;
 17  /
10 11450 2262.94 6084.43
20 5470.4 1469.5 3282.81
30 5248.96 1707.54 2483.95

PL/SQL procedure successfully completed.

SQL> @ SALARY.SQL;
10  11450     2262.94   6084.43
20  5470.4   1469.5      3282.81
30  5248.96 1707.54    2483.95

PL/SQL procedure successfully completed.

Comments

Popular posts from this blog

Write a program to add two number using inline function in C++?

Traversing of elements program with algorithm and Flowchart