Download PL/SQL User's Guide and Reference, Release 8.0

Transcript
Overloading
And, you might write the next procedure to initialize the index-by table named
sal_tab:
PROCEDURE initialize (tab OUT RealTabTyp, n INTEGER) IS
BEGIN
FOR i IN 1..n LOOP
tab(i) := 0.0;
END LOOP;
END initialize;
Because the processing in these two procedures is the same, it is logical to give
them the same name.
You can place the two overloaded initialize procedures in the same block,
subprogram, or package. PL/SQL determines which of the two procedures is being
called by checking their formal parameters.
Consider the example below. If you call initialize with a DateTabTyp
parameter, PL/SQL uses the first version of initialize. But, if you call
initialize with a RealTabTyp parameter, PL/SQL uses the second version.
DECLARE
TYPE DateTabTyp IS TABLE OF DATE
TYPE RealTabTyp IS TABLE OF REAL
hiredate_tab DateTabTyp;
comm_tab
RealTabTyp;
indx
BINARY_INTEGER;
...
BEGIN
indx := 50;
initialize(hiredate_tab, indx);
initialize(comm_tab, indx);
...
END;
INDEX BY BINARY_INTEGER;
INDEX BY BINARY_INTEGER;
-- calls first version
-- calls second version
Restrictions
Only local or packaged subprograms can be overloaded. Therefore, you cannot
overload stand-alone subprograms. Also, you cannot overload two subprograms if
their formal parameters differ only in name or parameter mode. For example, you
cannot overload the following two procedures:
PROCEDURE reconcile (acct_no IN INTEGER) IS
BEGIN
...
END;
Subprograms 7-19