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

  1. rem 
  2. rem $Header: sample2.sql 7020100.1 94/09/28 16:39:49 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      sample2.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 program 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.  
  33.     FOR i IN 1..5 LOOP
  34.     FETCH c1 INTO my_ename, my_empno, my_sal;
  35.     EXIT WHEN c1%NOTFOUND;     /* in case the number requested is more *
  36.                   * than the total number of employees   */
  37.     INSERT INTO temp VALUES (my_sal, my_empno, my_ename);
  38.         COMMIT;
  39.     END LOOP;
  40.  
  41.     CLOSE c1;
  42. END;
  43. /
  44.