A local module is a procedure or function that is defined in the declaration section of a PL/SQL block (anonymous or named). This module is considered local because it is defined only within the parent PL/SQL block. It cannot be called by any other PL/SQL blocks defined outside that enclosing block.
Figure 16-4 shows how blocks that are external to a procedure definition cannot “cross the line” into the procedure to directly invoke any local procedures or functions.
Figure 16-4. Local modules are hidden and inaccessible outside the program
The syntax for defining the procedure or function is exactly the same as that used for creating standalone modules.
The following anonymous block, for example, declares a local procedure:
DECLARE PROCEDURE show_date (date_in IN DATE) IS BEGIN DBMS_OUTPUT.PUT_LINE (TO_CHAR (date_in, 'Month DD, YYYY'); END; BEGIN ... END;
Local modules must be located after all of the other declaration statements in the declaration section. You must declare your variables, cursors, exceptions, types, records, tables, and so on before you type in the first PROCEDURE or FUNCTION keyword.
The following sections explore the benefits of local modules and offer a number of examples.
There are two central reasons to create local modules:
This is the most common ...