create or replace package test is
function Test1(p1 in varchar2) return varchar2;
function Test1(p1 in number) return varchar2;
function Test1(p1 in date) return varchar2;
function Test1(p1 in varchar2, p2 in varchar2) return number;
procedure Test1(p1 in varchar2);
end;
/
create or replace package body test is
function Test0(p1 in varchar2, p2 in varchar2) return varchar2 is
begin
dbms_output.put_line('para1 = ' || p1);
dbms_output.put_line('para1 = ' || p2);
return p1 || p2;
end;
function Test1(p1 in varchar2) return varchar2 is
begin
dbms_output.put_line('Test1 - 1 varchar2 実行');
return Test0(p1, '');
end;
function Test1(p1 in number) return varchar2 is
begin
dbms_output.put_line('Test1 - 2 number 実行');
return Test0(to_char(p1), '');
end;
function Test1(p1 in date) return varchar2 is
begin
dbms_output.put_line('Test1 - 3 date 実行');
return Test0(to_char(p1, 'yyyy.mm.dd'), '');
end;
function Test1(p1 in varchar2, p2 in varchar2) return number is
begin
dbms_output.put_line('Test1 - 4 varchar2 実行');
return to_number(Test0(p1, p2));
end;
procedure Test1(p1 in varchar2) is
a varchar2(2000);
begin
dbms_output.put_line('Test1 - 5 varchar2 実行');
a := Test0(p1, '');
end;
end;
/
■オーバーロード処理テスト
set serveroutput on;
variable rcd varchar2(200);
execute :rcd := test.test1('aaa');
print rcd;
set serveroutput on;
variable rcd varchar2(200);
execute :rcd := test.test1(100);
print rcd;
set serveroutput on;
variable rcd varchar2(200);
execute :rcd := test.test1(sysdate);
print rcd;
set serveroutput on;
variable rcd varchar2(200);
execute :rcd := test.test1('123', '456');
print rcd;
set serveroutput on;
execute test.test1('123');