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
IN OUT Mode An IN OUT parameter passes initial values to the subprogram being called and return efficient values to the caller. Within the subprogram, an IN OUT parameter acts

Keyword & Parameter Description: boolean_expression: This is an expression which yields the Boolean value that is TRUE, FALSE, & NULL. character_expression: This

I need SQL , WP SQL Expert Project Description: Expert required to modify WP SQL query. Skills required are MySQL, SQL, PHP, Wordpress

DBMS_PIPE: The Package DBMS_PIPE allows various sessions to communicate over the named pipes. (A pipe is a region of memory used by one of the process to pass information to

What Is a Record  ? A record is a group of related data items that stored in the fields, each with its own name and datatype. Assume that you have different data about an em

Project Description: I want to write some SQL statements. The things I need are between pages 5-7. The only problem is that i want it till tomorrow. Skills required is SQL

Use of COUNT in SQL It describes and discusses various general methods of expressing constraints, eventually noting that support for "=" with relation operands is sufficient f

Predicate - SQL Consider the declarative sentence-a proposition-that is used to introduce this topic:  "Student S1, named Anne, is enrolled on course C1." Recall that th

Nested Tables versus Index-by Tables The Index-by tables and nested tables are just similar. For e.g.  They have similar structure and their individual elements are accessed in

Assigning and Comparing Collections One collection can be assigned to other by an SELECT, INSERT, UPDATE, or FETCH statement, an assignment statement, or by a subprogram call. A