home *** CD-ROM | disk | FTP | other *** search
- rem
- rem $Header: sample2.sql,v 1002100.2 90/01/11 17:02:30 nsalah Exp $ sample2.sql Copyr (c) 1989 Oracle
- rem
- rem V6PLS10021,DISK$DEV9:[PLS.DEMO.10021]
- /*
- ** This program uses a cursor to select the 5 highest paid employees
- ** from the EMP table.
- **
- ** Copyright (c) 1989 by Oracle Corporation
- */
-
- DECLARE
- CURSOR c1 is
- SELECT ename, empno, sal FROM emp
- ORDER BY sal DESC; -- start with highest paid employee
- my_ename CHAR(10);
- my_empno NUMBER(4);
- my_sal NUMBER(7,2);
-
- BEGIN
- OPEN c1;
-
- FOR i IN 1..5 LOOP
- FETCH c1 INTO my_ename, my_empno, my_sal;
- EXIT WHEN c1%NOTFOUND; /* in case the number requested is more *
- * than the total number of employees */
- INSERT INTO temp VALUES (my_sal, my_empno, my_ename);
- COMMIT;
- END LOOP;
-
- CLOSE c1;
- END;
- /
-