Overloading, PL-SQL Programming

Overloading

The PL/SQL overloads the subprogram names. That is, you can use similar name for few different subprograms as long as their formal parameters differ in the number, order, or datatype family.

Assume that you want to initialize the first n rows in two index-by tables that were declared as shown below:

DECLARE

TYPE DateTabTyp IS TABLE OF DATE INDEX BY BINARY_INTEGER;

TYPE RealTabTyp IS TABLE OF REAL INDEX BY BINARY_INTEGER;

hiredate_tab DateTabTyp;

sal_tab RealTabTyp;

You may write the procedure below to initialize the index-by table named hiredate_tab:

PROCEDURE initialize (tab OUT DateTabTyp, n INTEGER) IS

BEGIN

FOR i IN 1..n LOOP

tab(i) := SYSDATE;

END LOOP;

END initialize;

And, you may write the next procedure to initialize the index-by table named sal_tab as:

PROCEDURE initialize (tab OUT RealTabTyp, n INTEGER) IS

BEGIN

FOR i IN 1..n LOOP

tab(i) := 0.0;

END LOOP;

END initialize;

As the processing in these two procedures are similar, it is logical to give them the similar name.

You can position the two overloaded initialize procedures in similar subprogram, block, or package. The PL/SQL determines that which of the two procedures is being called by checking their formal parameters.

Consider the illustration below. If you call initialize with a DateTabTyp parameter, the PL/SQL uses the first version of initialize. But, if you call the initialize with a RealTabTyp parameter, then the PL/SQL uses the second version.

DECLARE

TYPE DateTabTyp IS TABLE OF DATE INDEX BY BINARY_INTEGER;

TYPE RealTabTyp IS TABLE OF REAL INDEX BY BINARY_INTEGER;

hiredate_tab DateTabTyp;

comm_tab RealTabTyp;

indx BINARY_INTEGER;

BEGIN

indx := 50;

initialize(hiredate_tab, indx); -- calls first version

initialize(comm_tab, indx); -- calls second version

Posted Date: 10/5/2012 5:38:34 AM | Location : United States







Related Discussions:- Overloading, Assignment Help, Ask Question on Overloading, Get Answer, Expert's Help, Overloading Discussions

Write discussion on Overloading
Your posts are moderated
Related Questions
Using a Join on 2 tables, select all columns and all rows from the tables without the use of a Cartesian product. Query: SELECT * FROM EMPLOYEE1 JOIN CONTRACT ON EMPLOYEE

Effects of NULL for UNIQUE Specification When a UNIQUE specification u for base table t includes a column c that is not subject to a NOT NULL constraint, the appearance of sev

Many of the reports generated from the system calculate the total dollars in purchases for a shopper. Complete the following steps to create a function named TOT_PURCH_SF that acce

How Calls Are Resolved? The figure shows that how the PL/SQL compiler resolves the subprogram calls. When the compiler encounters the procedure or function call, it tries to di

Obtaining a natural join by specifying the common columns Synatax: SELECT * FROM IS_CALLED JOIN IS_ENROLLED_ON USING ( StudentId ) However, a named columns join doe

Functions   The function is a subprogram that calculates a value. The Functions and procedures are structured similar, except that the functions have a RETURN clause. You can

Implicit Cursor is declared and used by the oracle environment internally. while the explicit cursor is declared and used by the external user. more over implicitly cursors are no

Managing Cursors The PL/SQL uses 2 types of cursors: implicit and explicit. The PL/SQL declares a cursor implicitly for all the SQL data manipulation statements, including th

Tables within a Table - SQL Figure here is an exact copy of the one in the theory book and as before it is just an alternative way of representing some of the information con

Initializing and Referencing Collections Until you initialize a collection, a nested table or varray is automatically null (i.e. the collection itself is null, not its elements)