Functions and procedures in packages can be overloaded. The following package TEST has two procedures called print_number, which behave differently depending on parameters they are called with.
create or replace package TEST is
procedure print_number(p_number in integer);
procedure print_number(p_number in varchar2);
end TEST;
/
create or replace package body TEST is
procedure print_number(p_number in integer) is
begin
dbms_output.put_line('Digit: ' || p_number);
end;
procedure print_number(p_number in varchar2) is
begin
dbms_output.put_line('String: ' || p_number);
end;
end TEST;
/
We call both procedures. The first with integer parameter, the second with varchar2.
set serveroutput on;
-- call the first procedure
exec test.print_number(3);
-- call the second procedure
exec test.print_number('three');
The output of the above script is:
SQL>
Digit: 3
PL/SQL procedure successfully completed
String: three
PL/SQL procedure successfully completed
Only local or packaged subprograms, or type methods, can be overloaded. Therefore, you cannot overload standalone subprograms. Also, you cannot overload two subprograms if their formal parameters differ only in name or parameter mode