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

  1. rem 
  2. rem $Header: examp9.sql,v 1002100.2 90/01/11 16:57:34 nsalah Exp $ examp9.sql Copyr (c) 1989 Oracle
  3. rem 
  4. rem V6PLS10021,DISK$DEV9:[PLS.DEMO.10021]
  5. /*
  6. ** This block returns a number from each of two tables, then
  7. ** inserts the sum of the numbers into a third table.  It stops
  8. ** when all rows have been fetched from either of the two tables.
  9. **
  10. ** Copyright (c) 1989 by Oracle Corporation
  11. */
  12.  
  13. DECLARE
  14.     CURSOR num1_cur IS SELECT num FROM num1_tab
  15.         ORDER BY sequence;
  16.     CURSOR num2_cur IS SELECT num FROM num2_tab
  17.         ORDER BY sequence;
  18.     num1    num1_tab.num%TYPE;
  19.     num2    num2_tab.num%TYPE;
  20.     pair_num    NUMBER := 0;
  21. BEGIN
  22.     OPEN num1_cur;
  23.     OPEN num2_cur;
  24.     LOOP   -- loop through the two tables and get
  25.            -- pairs of numbers
  26.         FETCH num1_cur INTO num1;
  27.         FETCH num2_cur INTO num2;
  28.         IF (num1_cur%FOUND) AND (num2_cur%FOUND) THEN
  29.             pair_num := pair_num + 1;
  30.             INSERT INTO sum_tab VALUES (pair_num, num1 + num2);
  31.         ELSE
  32.             EXIT;
  33.         END IF;
  34.     END LOOP;
  35.     CLOSE num1_cur;
  36.     CLOSE num2_cur;
  37. END;
  38. /
  39.