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
Create a Oracle procedure to produce vertical output format when selecting rows from a database table.

Remote Operations: As the illustration shows below, the PL/SQL subprograms can execute the dynamic SQL statements which refer to the objects on a remote database: PROCEDURE

Rollback Behavior When a FORALL statement fails, the database changes are rolled back to an implicit savepoint marked before each of the SQL statement execution. The Changes t

Manipulating Collections Within PL/SQL, the collections add procedural power and flexibility. The biggest benefit is that your program can compute subscripts to process the spec

Parameter and Keyword Description: collection_name: This keyword identifies the index-by table, nested table, or varray formerly declared within the present scope. cu

I need to write one function and one procedure to query a Oracle 10.1 DB using PL SQL. I have the schema and exact queries...along with work Ive started and a template to put the a

Using research notes and Oracle documentation plan and execute an upgrade of an installation of Oracle 10g to Oracle 11g release 1. To do this you must show in screen shots and wri

LEVEL You use the LEVEL with the SELECT CONNECT BY statement to categorize rows from a database table into a tree structure. The LEVEL returns the level number of a node in a

Comparison Operators Usually, you use the comparison operators in the WHERE clause of a data manipulation statement to form the predicates, that compare one expression to anot

Using EXTEND To enlarge the size of a collection, use EXTEND. This process has 3 forms. The EXTEND appends one null element to a collection. And the EXTEND(n) appends n null e