15.2 Review of PL/SQL Block StructureChapter 1, Introduction to PL/SQL , provided a brief introduction to the PL/SQL block and its structure. Before we explore the construction of modules in PL/SQL, let's take a more detailed look at the PL/SQL block. PL/SQL is a block-structured language. Each of the basic programming units you write to build your application is (or should be) a logical unit of work. The PL/SQL block allows you to reflect that logical structure in the physical design of your programs. The block determines both the scope of identifiers (the area of code in which a reference to the identifier can be resolved) and the way in which exceptions are handled and propagated. A block may also contain nested sub-blocks of code, each with its own scope. There is a common block structure to all the different types of modules. The block is broken up into four different sections, as follows:
Figure 15.1 shows the structure of the PL/SQL block. Figure 15.1: The PL/SQL block structure for procedures and functions15.2.1 Sequence of Section ConstructionThe ordering of the sections in a block corresponds to the way you would write your programs and the way they are executed.
The declaration and exception sections are optional in any PL/SQL block, but you must always have at least one executable statement in a block. 15.2.2 PL/SQL Block Structure ExamplesFigures Figure 15.2 through Figure 15.4 illustrate several different ways that PL/SQL blocks can be constructed. Figure 15.2: A procedure containing all four sectionsFigure 15.3: A function without an exception sectionNow that you understand the basic components of a PL/SQL block, let's explore the ways you can use this structure in your programming. Copyright (c) 2000 O'Reilly & Associates. All rights reserved. |
|