home *** CD-ROM | disk | FTP | other *** search
- rem
- rem $Header: sample3.sql,v 1002100.2 90/01/11 17:02:59 nsalah Exp $ sample3.sql Copyr (c) 1989 Oracle
- rem
- rem V6PLS10021,DISK$DEV9:[PLS.DEMO.10021]
- /*
- ** Shows block structure and the scoping of variables associated with
- ** block structure. There is an outer block that declares two variables,
- ** X and COUNTER. This block loops four times. Within this loop is
- ** another block. This block redeclares a local copy of X, and also loops
- ** four times. The values inserted into the TEMP table show that the two
- ** X's are indeed different.
- **
- ** Copyright (c) 1989 by Oracle Corporation
- */
-
- DECLARE
- x NUMBER := 0;
- counter NUMBER := 0;
- BEGIN
- FOR i IN 1..4 LOOP
- x := x + 1000;
- counter := counter + 1;
- INSERT INTO temp VALUES (x, counter, 'in OUTER loop');
-
- /* start an inner block */
- DECLARE
- x NUMBER := 0; -- this is a local copy of x
- BEGIN
- FOR i IN 1..4 LOOP
- x := x + 1; -- this increments the local copy of x
- counter := counter + 1;
- INSERT INTO temp VALUES (x, counter, 'inner loop');
- END LOOP;
- END;
-
- END LOOP;
- COMMIT;
- END;
- /
-