Debian Codegraph @

doc/sql.extensions/README.leave_labels

raw
1 ----------------------------------------
2 PSQL labels and LEAVE statement (FB 2.0)
3 ----------------------------------------
4
5 Function:
6 Allows to stop execution of the current block and unwind to the specified label.
7 After that execution continues from the statement following by the terminated loop statement.
8
9 Author:
10 Dmitry Yemanov <[email protected]>
11
12 Syntax rules:
13 <label_name>: <loop_statement>
14 ...
15 LEAVE [<label_name>]
16
17 Where <loop_statement> is one of: WHILE, FOR SELECT, FOR EXECUTE STATEMENT
18
19 Example(s):
20 1. FOR
21 SELECT COALESCE(RDB$SYSTEM_FLAG, 0), RDB$RELATION_NAME
22 FROM RDB$RELATIONS
23 ORDER BY 1
24 INTO :RTYPE, :RNAME
25 DO
26 BEGIN
27 IF (RTYPE = 0) THEN
28 SUSPEND;
29 ELSE
30 LEAVE; -- exits current loop
31 END
32
33 2. CNT = 100;
34 L1:
35 WHILE (CNT >= 0) DO
36 BEGIN
37 IF (CNT < 50) THEN
38 LEAVE L1; -- exists WHILE loop
39 CNT = CNT - l;
40 END
41
42 3. STMT1 = 'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS';
43 L1:
44 FOR
45 EXECUTE STATEMENT :STMT1 INTO :RNAME
46 DO
47 BEGIN
48 STMT2 = 'SELECT RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE RDB$RELATION_NAME = ';
49 L2:
50 FOR
51 EXECUTE STATEMENT :STMT2 || :RNAME INTO :FNAME
52 DO
53 BEGIN
54 IF (RNAME = 'RDB$DATABASE') THEN
55 LEAVE L1; -- exits the outer loop
56 ELSE IF (RNAME = 'RDB$RELATIONS') THEN
57 LEAVE L2; -- exits the inner loop
58 ELSE
59 SUSPEND;
60 END
61 END
62
63 Note(s):
64 LEAVE without explicit lable means interrupting the current (most inner) loop.