home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / EXAMP12.SQL < prev    next >
Encoding:
Text File  |  1995-05-18  |  1.4 KB  |  49 lines

  1. rem 
  2. rem $Header: examp12.sql 7020100.1 94/09/28 16:39:55 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      examp12.sql - <one-line expansion of the name>
  7. Rem    DESCRIPTION
  8. Rem      <short description of component this file declares/defines>
  9. Rem    RETURNS
  10. Rem 
  11. Rem    NOTES
  12. Rem      <other useful comments, qualifications, etc.>
  13. Rem    MODIFIED   (MM/DD/YY)
  14. Rem     rvasired   05/12/92 -  Creation 
  15. /*
  16. ** This block returns a number from each of two tables, then
  17. ** inserts the sum of the numbers into a third table.  It stops
  18. ** when all rows have been fetched from either of the two tables.
  19. **
  20. ** Copyright (c) 1989,1992 by Oracle Corporation
  21. */
  22.  
  23. DECLARE
  24.     CURSOR num1_cur IS SELECT num FROM num1_tab
  25.         ORDER BY sequence;
  26.     CURSOR num2_cur IS SELECT num FROM num2_tab
  27.         ORDER BY sequence;
  28.     num1      num1_tab.num%TYPE;
  29.     num2      num2_tab.num%TYPE;
  30.     pair_num  NUMBER := 0;
  31. BEGIN
  32.     OPEN num1_cur;
  33.     OPEN num2_cur;
  34.     LOOP   -- loop through the two tables and get
  35.            -- pairs of numbers
  36.         FETCH num1_cur INTO num1;
  37.         FETCH num2_cur INTO num2;
  38.         IF (num1_cur%FOUND) AND (num2_cur%FOUND) THEN
  39.             pair_num := pair_num + 1;
  40.             INSERT INTO sum_tab VALUES (pair_num, num1 + num2);
  41.         ELSE
  42.             EXIT;
  43.         END IF;
  44.     END LOOP;
  45.     CLOSE num1_cur;
  46.     CLOSE num2_cur;
  47. END;
  48. /
  49.