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

  1. rem 
  2. rem $Header: examp10.sql,v 1002100.2 90/01/11 16:58:06 nsalah Exp $ examp10.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.         EXIT WHEN (num1_cur%NOTFOUND) OR (num2_cur%NOTFOUND);
  29.         pair_num := pair_num + 1;
  30.         INSERT INTO sum_tab VALUES (pair_num, num1 + num2);
  31.     END LOOP;
  32.     CLOSE num1_cur;
  33.     CLOSE num2_cur;
  34. END;
  35. /
  36.