Monday, December 3, 2012

0 PL/SQL overloading package

We can create the package with PLSQL and have the ability for overloading just like any other OO language.

Here is the sample:

Lets create the sample package:

The package can take 2 types of the input, character or numeric.

create or replace package mypack1
IS
    procedure mysp1( char_var IN varchar2);
    procedure mysp1( num_var IN number);
END;
/
 
create or replace package body mypack1
IS
    procedure mysp1( char_var IN varchar2)
    is
    BEGIN
        dbms_output.put_line ( 'I am char:' || char_var);
    END;
    procedure mysp1( num_var IN number)
    is
    BEGIN
        dbms_output.put_line ( 'I am number:' || num_var);
    END;
END mypack1;
/

 

Here is the sample execution;

We need to set the serveroutput on in order to output the result to standard out.

set serveroutput on
exec mypack1.mysp1('Happy Holiday');
exec mypack1.mysp1(10101010);

image

0 comments:

Post a Comment

 

SQL Panda Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates