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

  1. rem 
  2. rem $Header: examp13.sql,v 1002100.2 90/01/11 17:00:21 nsalah Exp $ examp13.sql Copyr (c) 1989 Oracle
  3. rem 
  4. rem V6PLS10021,DISK$DEV9:[PLS.DEMO.10021]
  5. /*
  6. ** This block calculates the total of all the wages (salary and
  7. ** commission) paid to employees in department 20.  It also counts
  8. ** how many of these people have salaries above $2000.00, and how
  9. ** many of them have commissions higher than their salaries.
  10. **
  11. ** Copyright (c) 1989 by Oracle Corporation
  12. */
  13.  
  14. DECLARE
  15.     CURSOR emp_cursor(dnum NUMBER) IS
  16.         SELECT sal, comm FROM emp WHERE deptno = dnum;
  17.     total_wages        NUMBER(11,2) := 0;
  18.     high_paid        NUMBER(4) := 0;
  19.     higher_comm        NUMBER(4) := 0;
  20. BEGIN
  21.     /* The number of iterations will equal the number of rows *
  22.      * returned by emp_cursor.                                */
  23.     FOR emp_record IN emp_cursor(20) LOOP
  24.         emp_record.comm := NVL(emp_record.comm, 0);
  25.         total_wages := total_wages + emp_record.sal +
  26.             emp_record.comm;
  27.         IF emp_record.sal > 2000.00 THEN
  28.             high_paid := high_paid + 1;
  29.         END IF;
  30.         IF emp_record.comm > emp_record.sal THEN
  31.             higher_comm := higher_comm + 1;
  32.         END IF;
  33.     END LOOP;
  34.     INSERT INTO temp VALUES (high_paid, higher_comm,
  35.         'Total Wages: ' || TO_CHAR(total_wages));
  36.     COMMIT;
  37. END;
  38. /
  39.