home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a524 / 37.ddi / demo / sample2.sql < prev    next >
Encoding:
Text File  |  1991-03-04  |  812 b   |  34 lines

  1. rem 
  2. rem $Header: sample2.sql,v 1002100.2 90/01/11 17:02:30 nsalah Exp $ sample2.sql Copyr (c) 1989 Oracle
  3. rem 
  4. rem V6PLS10021,DISK$DEV9:[PLS.DEMO.10021]
  5. /*
  6. ** This program uses a cursor to select the 5 highest paid employees 
  7. ** from the EMP table.
  8. **
  9. ** Copyright (c) 1989 by Oracle Corporation
  10. */
  11.  
  12. DECLARE
  13.     CURSOR c1 is
  14.     SELECT ename, empno, sal FROM emp
  15.     ORDER BY sal DESC;           -- start with highest paid employee
  16.     my_ename    CHAR(10);
  17.     my_empno    NUMBER(4);
  18.     my_sal    NUMBER(7,2);
  19.  
  20. BEGIN
  21.     OPEN c1;
  22.  
  23.     FOR i IN 1..5 LOOP
  24.     FETCH c1 INTO my_ename, my_empno, my_sal;
  25.     EXIT WHEN c1%NOTFOUND;         /* in case the number requested is more *
  26.                       * than the total number of employees   */
  27.     INSERT INTO temp VALUES (my_sal, my_empno, my_ename);
  28.         COMMIT;
  29.     END LOOP;
  30.  
  31.     CLOSE c1;
  32. END;
  33. /
  34.