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

  1. rem 
  2. rem $Header: sample3.sql,v 1002100.2 90/01/11 17:02:59 nsalah Exp $ sample3.sql Copyr (c) 1989 Oracle
  3. rem 
  4. rem V6PLS10021,DISK$DEV9:[PLS.DEMO.10021]
  5. /*
  6. ** Shows block structure and the scoping of variables associated with
  7. ** block structure.  There is an outer block that declares two variables,
  8. ** X and COUNTER.  This block loops four times.  Within this loop is
  9. ** another block.  This block redeclares a local copy of X, and also loops
  10. ** four times.  The values inserted into the TEMP table show that the two
  11. ** X's are indeed different.
  12. **
  13. ** Copyright (c) 1989 by Oracle Corporation
  14. */
  15.  
  16. DECLARE
  17.     x        NUMBER := 0;
  18.     counter  NUMBER := 0;
  19. BEGIN
  20.     FOR i IN 1..4 LOOP
  21.     x := x + 1000;
  22.     counter := counter + 1;
  23.         INSERT INTO temp VALUES (x, counter, 'in OUTER loop');
  24.  
  25.     /* start an inner block */
  26.         DECLARE
  27.         x NUMBER := 0;          -- this is a local copy of x
  28.     BEGIN
  29.         FOR i IN 1..4 LOOP
  30.         x := x + 1;         -- this increments the local copy of x
  31.         counter := counter + 1;
  32.             INSERT INTO temp VALUES (x, counter, 'inner loop');
  33.         END LOOP;
  34.     END;
  35.  
  36.     END LOOP;
  37.     COMMIT;
  38. END;
  39. /
  40.