home *** CD-ROM | disk | FTP | other *** search
- rem
- rem $Header: examp9.sql,v 1002100.2 90/01/11 16:57:34 nsalah Exp $ examp9.sql Copyr (c) 1989 Oracle
- rem
- rem V6PLS10021,DISK$DEV9:[PLS.DEMO.10021]
- /*
- ** This block returns a number from each of two tables, then
- ** inserts the sum of the numbers into a third table. It stops
- ** when all rows have been fetched from either of the two tables.
- **
- ** Copyright (c) 1989 by Oracle Corporation
- */
-
- DECLARE
- CURSOR num1_cur IS SELECT num FROM num1_tab
- ORDER BY sequence;
- CURSOR num2_cur IS SELECT num FROM num2_tab
- ORDER BY sequence;
- num1 num1_tab.num%TYPE;
- num2 num2_tab.num%TYPE;
- pair_num NUMBER := 0;
- BEGIN
- OPEN num1_cur;
- OPEN num2_cur;
- LOOP -- loop through the two tables and get
- -- pairs of numbers
- FETCH num1_cur INTO num1;
- FETCH num2_cur INTO num2;
- IF (num1_cur%FOUND) AND (num2_cur%FOUND) THEN
- pair_num := pair_num + 1;
- INSERT INTO sum_tab VALUES (pair_num, num1 + num2);
- ELSE
- EXIT;
- END IF;
- END LOOP;
- CLOSE num1_cur;
- CLOSE num2_cur;
- END;
- /
-