The relationship between blocks can be declared in a Structured Programming Language (SPL) program. The relationship determines the ability to invoke subprograms and access identifiers that are declared within a block. This topic introduces terms related to block relationships.
- A block is the basic SPL structure. It consists of an optional declaration section, a mandatory executable section, and an optional exception section. Blocks implement standalone procedures and function programs, anonymous blocks, triggers, packages, subprocedures, and subfunctions.
- Identifiers are names that are assigned to elements of an SPL program, such as variables, cursors, types, or subprograms. If an identifier is local to a block, the identifier is declared within the declaration topic of the given block. Such local identifiers are accessible from the executable section and the optional exception section of the block.
- A parent block contains the declaration of child blocks.
- Descendant blocks are a set of blocks that form the child relationship that starts from a given parent block.
- Ancestor blocks are a set of blocks that form the parental relationship that starts from a given child block.
- A hierarchy consists of a set of descendant or ancestor blocks.
- A level is the ordinal number of a given block from the highest ancestor block. For a standalone procedure, all of the subprograms that are declared within the declaration topic of this procedure are at the same level. If you call this procedure at level 1, additional subprograms within the declaration topic of the subprograms that are declared in the standalone procedure are at the next level, which is level 2.
- Sibling blocks are a set of blocks that have the same parent block. This indicates that all of the sibling blocks are locally declared in the same block. Sibling blocks are at the same level.
The following example shows a set of blocks and their relationships to their surrounding blocks in a procedure declaration section.
The two vertical lines on the left side of the blocks indicate that two pairs of sibling blocks exist. block_1a and block_1b are one pair, and block_2a and block_2b are the other pair.
The relationship of each block with its ancestors is shown on the right side of the blocks. When the program progresses up the hierarchy from the lowest-level child blocks, three hierarchical paths are formed. The first path consists of block_0, block_1a, block_2a, and block_3. The second path consists of block_0, block_1a, and block_2b. The third path consists of block_0, block_1b, and block_2b.
CREATE PROCEDURE block_0 IS . +---- PROCEDURE block_1a ------- Local to block_0 | IS | . | | . | | . | | +-- PROCEDURE block_2a ---- Local to block_1a and descendant | | IS of block_0 | | . | | | . | | | . | | | PROCEDURE block_3 -- Local to block_2a and descendant | | IS of block_1a, and block_0 | Siblings . | | | . | | | . | | | END block_3; | | | END block_2a; | | +-- PROCEDURE block_2b ---- Local to block_1a and descendant | | IS of block_0 Siblings | , | | | . | | | . | | +-- END block_2b; | | | | END block_1a; ---------+ +---- PROCEDURE block_1b; ------- Local to block_0 | IS | . | | . | | . | | PROCEDURE block_2b ---- Local to block_1b and descendant | IS of block_0 | . | | . | | . | | END block_2b; | | | +---- END block_1b; ---------+ BEGIN . . . END block_0;