-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathinner_loop_block.sql
53 lines (47 loc) · 1.4 KB
/
inner_loop_block.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--
-- Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
--
-- Licensed under the Universal Permissive License v 1.0 as shown
-- at http://oss.oracle.com/licenses/upl
--
Rem
Rem NAME
Rem pls_sample3.sql - <one-line expansion of the name>
Rem DESCRIPTION
Rem <short description of component this file declares/defines>
Rem RETURNS
Rem
Rem NOTES
Rem renamed from sample3.sql to pls_sample3.sql
Rem
/*
** This example illustrates block structure and scope rules. An
** outer block declares two variables named X and COUNTER, and loops four
** times. Inside the loop is a sub-block that also declares a variable
** named X. The values inserted into the TEMP table show that the two
** X's are indeed different.
**
** Copyright (c) 1989,1992, 1999 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 version of x
BEGIN
FOR i IN 1..4 LOOP
x := x + 1; -- this increments the local x
counter := counter + 1;
INSERT INTO temp VALUES (x, counter, 'inner loop');
END LOOP;
END;
END LOOP;
COMMIT;
END;
/