 |
|
Oracle Tips by Burleson |
Local
Modules
A local module is a procedure or function defined
in the declaration section of another PL/SQL block.
Because it is defined in a block, its scope is only in the block that
defined it. The local module can not be called or executed by code
outside of the defining block. The example below is an anonymous
PL/SQL block that has a function defined in the declaration section.
SQL> declare
2 v_test varchar2(40) := '&string';
3
4 function get_length
5 (v_str IN varchar2)
6 return number
7 as
8 begin
9 return length(v_str);
10 end;
11 begin
12 dbms_output.put_line(v_test||' has
'||get_length(v_test)||' characters.');
13 end;
14 /
Enter value for string: Smitherdoodle
old 2: v_test varchar2(40) := '&string';
new 2: v_test varchar2(40) := 'Smitherdoodle';
Smitherdoodle has 13 characters.
PL/SQL procedure successfully completed.
The function get_length is defined in the
anonymous block above and exist only within that block. There are a
number of reasons to use local modules. First, by creating functions and
procedures as local modules they are hidden from outside the defining
block, allowing added functionality and code reuse while maintaining
modularity. The local modules are hidden from other code within the
containing package.
This protects object names and actions from code
outside the defining block. Another benefit is that if used properly,
local modules can make the code easier to read and maintain. However,
these benefits can also be detractors. Local modules can not be used
by code outside of the defining block, thereby limiting code reuse to
only the defining block. Extensive use of local modules can lead to
sections of code that perform the same functions located in multiple
modules. This can result in lower code quality, maintainability and
performance.
The above book excerpt is from:
Easy Oracle PL/SQL Programming
Get Started
Fast with Working PL/SQL Code Examples
ISBN 0-9759135-7-3
John Garmany
http://www.rampant-books.com/book_2005_1_easy_plsql.htm
|