Function Overloading [message #346571] |
Mon, 08 September 2008 23:15  |
honeysn
Messages: 2 Registered: September 2008
|
Junior Member |
|
|
Hi,
I have a overloading function as shown below:
******** package **************************
create or replace package test_load is
function print_it (p_arg in date) return varchar2;
function print_it (p_arg in varchar2) return number;
end;
****************************************************
************* Package Body ************************
create or replace package body test_load
is
function print_it(p_arg in date) return varchar2
is
begin
dbms_output.put_line('Inside date');
return to_char(p_arg,'FmMonth, dd yyyy');
end;
function print_it(p_arg in varchar2) return number
is
begin
dbms_output.put_line('Inside varchar');
return to_number(p_arg,'999,999.00');
end;
end;
************************************************
I tried to invoke the first overloaded function using below commands:
var display_date varchar2(20)
exec :display_date:=test_load.print_it('08-Mar-01');
I am getting the error:
ORA-06502: PL/SQL: numeric or value error
Its because second overloaded function (with input as varchar) is getting called instead of first overloaded function (with input as date).
Please suggest how to make sure first overloaded function (with date input) is called, when pass date as input.
Thanks.
|
|
|
|
|
Re: Function Overloading [message #346577 is a reply to message #346571] |
Mon, 08 September 2008 23:34   |
honeysn
Messages: 2 Registered: September 2008
|
Junior Member |
|
|
Thanks guys for pointing out my mistake. Now I am able to execute the function properly ... I used following command
exec :display_date:=test_load.print_it(to_date('08-Mar-01'));
Now its considered as a date.
Thanks for your help.
[Updated on: Mon, 08 September 2008 23:46] Report message to a moderator
|
|
|
Re: Function Overloading [message #346600 is a reply to message #346577] |
Tue, 09 September 2008 01:44  |
 |
Michel Cadot
Messages: 68737 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote: | Now its considered as a date.
|
But is wrong in many environments:
SQL> select to_date('08-Mar-01') from dual;
select to_date('08-Mar-01') from dual
*
ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected
Regards
Michel
|
|
|