home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / EXAMP14.SQL < prev    next >
Encoding:
Text File  |  1995-05-18  |  1.0 KB  |  41 lines

  1. rem 
  2. rem $Header: examp14.sql 7020100.1 94/09/28 16:39:54 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      examp14.sql - <one-line expansion of the name>
  7. Rem    DESCRIPTION
  8. Rem      <short description of component this file declares/defines>
  9. Rem    RETURNS
  10. Rem 
  11. Rem    NOTES
  12. Rem      <other useful comments, qualifications, etc.>
  13. Rem    MODIFIED   (MM/DD/YY)
  14. Rem     rvasired   05/12/92 -  Creation 
  15. /*
  16. ** This block uses a cursor to select the 5 highest-paid employees 
  17. ** from the EMP table.
  18. **
  19. ** Copyright (c) 1989,1992 by Oracle Corporation
  20. */
  21.  
  22. DECLARE
  23.     CURSOR c1 is
  24.     SELECT ename, empno, sal FROM emp
  25.     ORDER BY sal DESC;   -- start with highest-paid employee
  26.     my_ename  CHAR(10);
  27.     my_empno  NUMBER(4);
  28.     my_sal    NUMBER(7,2);
  29.  
  30. BEGIN
  31.     OPEN c1;
  32.     LOOP
  33.     FETCH c1 INTO my_ename, my_empno, my_sal;
  34.     EXIT WHEN (c1%ROWCOUNT > 5) OR (c1%NOTFOUND);
  35.     INSERT INTO temp VALUES (my_sal, my_empno, my_ename);
  36.         COMMIT;
  37.     END LOOP;
  38.     CLOSE c1;
  39. END;
  40. /
  41.