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
Joining in SQL Joining IS_CALLED and IS_ENROLLED_ON in SQL SELECT * FROM IS_CALLED NATURAL JOIN IS_ENROLLED_ON This is an example of an SQL table expression. I have been

Inner Join We have learned how to retrieve data from one table by using SELECT statement. But, as we have learned, normalized relational databases mean the data is spread betw

Effects of NULL for Table Expression Here's an important distinction between expressions denoting tables and expressions denoting multisets of rows: a table expression cannot

SQL Database: So, an SQL database is one whose symbols are organized into a collection of tables. Now, shows an SQL table as the current value of an SQL variable, ENROLMENT, b

FETCH Statement The FETCH statement retrieve rows of data one at a time from the result set of the multi-row query. The data is stored in fields or variables which correspond t

%ROWTYPE: This attribute gives a record type which represents a row in the database table or a row fetched from a formerly declared cursor. The Fields in the record and corresp

SQL outer join SELECT * FROM IS_CALLED NATURAL LEFT JOIN IS_ENROLLED_ON Note that adding LEFT to an invocation of CROSS JOIN has no effect unless the right-hand operand

Row Operators The Row operators return or reference the particular rows. ALL retains the duplicate rows in the result of a query or in an aggregate expression. The DISTINCT el

Logical Operators The logical operators AND, NOT, and OR follow the tri-state logic shown in table below. The AND and OR are binary operators; NOT is a unary operator.

OUT Mode An OUT parameter returns values to the caller of a subprogram. Within the subprogram, an OUT parameter act like a variable. That means that you can use an OUT formal