Overloading function
Hi all
create or replace package emp_pack is
function p1 (p_tvia_num movil.tvia_num%type,
p_chaluka_num movil.chaluka_num%type) return number ;
function p1 (p_tvianum movil.tvia_num%type,
p_chlaukanum%type,
p_polisanum%type) return number ;
end emp_pack;i'm posting only the specification
now
i'm trying to invoke the function :
exec emp_pack.p1(p_tvia_num=>99,p_chaluka_num=>0);
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'P1
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored '
i know that if i declare different name for the parameters and invoking the function with the parameter name it's suppose to work ,
am i right ? or this valid only to procedures ?
Thanks in Advanced
Naama
Edited by: naama on Jun 12, 2011 2:47 AM
Hi peter
Sorry my mistake , i copied the wrong script
CREATE OR REPLACE PACKAGE emp_pack IS
FUNCTION p1 (
p_tvia_num movil.tvia_num%TYPE,
p_chaluka_num movil.chaluka_num%TYPE
RETURN NUMBER;
FUNCTION p1 (
p_tvianum movil.tvia_num%TYPE,
p_chlaukanum movil.chaluka_num%TYPE,
p_polisanum movil.polisa_num%TYPE
RETURN NUMBER;
end emp_pack;/
o.k you right , and i also did
var g_num
execute :g_num := emp_pack.p1(p_tvia_num=>99, p_chaluka_num=>0)
and it's work
now i was wondering
from the beginning i wanted to do like this :
CREATE OR REPLACE PACKAGE emp_pack IS
FUNCTION p1 (
p_tvia_num movil.tvia_num%TYPE,
p_chaluka_num movil.chaluka_num%TYPE
RETURN NUMBER;
FUNCTION p1 (
p_tvia_num movil.tvia_num%TYPE,
p_chlauka_num movil.chaluka_num%TYPE,
p_polisa_num movil.polisa_num%TYPE
RETURN NUMBER;
--overloading function no.3
FUNCTION p1 (
p_polisa_num movil.polisa_num%TYPE ,
p_chlauka_num movil.chaluka_num%TYPE) return number ;
end emp_pack;i added one more function which get also two parameters of the same data type ,
and also gave the parameters of all the p1 function the same name ,
is it valid and if so , it this a poor pl/sql code , ok is it o.k writing like this ?
Thanks in Advanced
Naama
Edited by: naama on Jun 12, 2011 3:35 AM
Edited by: naama on Jun 12, 2011 3:36 AM
Similar Messages
-
Hi, i got a question in my exam paper which went:
Write a program in Java(using BlueJ) to generate the following pattern for the first 'n' number of rows using overloaded functions
Following is the output for 5 rows:
a) 123454321 b) .... c) ...................
1234 4321
123 321
12 21
1 1
The patterns are not important, but I dont understand what overloaded functions mean. Also i have heard about overloaded constructors and I would like to know what they are too. Ive searched on the internet but i cant get answers that explain it properly. Would be glad to receive some clarification. Thanks
Message was edited by:
OverkillWell I cant really predict the questions that will come in my exam will I? Now after my exam is over , i tried to solve many of the problems i couldn't get , and i solved most, but I could not solve some.
All im asking for is help in solving those.. why are you hostile about that ? -
I read a lot about �overloaded functions� . Are there any others way I can use overloaded functions besides having multiple constructors in a class?
Thanks
MarioA quick example is something like PrintStream.println(). Take a look at that to see how overloading can be used.
-
Calling an overloading function
Hi all,
How can I call an overloading function from outside the package without using the package name,
For example :
CREATE PACKAGE PACK
FUNCTION X(P_INTERVAL IN VARCHAR2, P_INTERVAL_VAL IN NUMBER, P_DATE_STR IN VARCHAR2) RETURN TIMESTAMP;
FUNCTION X(P_INTERVAL IN VARCHAR2, P_INTERVAL_VAL IN NUMBER, P_DATE_EXPR IN DATE) RETURN DATE;
FUNCTION X(P_INTERVAL IN VARCHAR2, P_INTERVAL_VAL IN NUMBER, P_DATE_EXPR IN TIMESTAMP) RETURN TIMESTAMP;
FUNCTION X(P_INTERVAL IN VARCHAR2, P_INTERVAL_VAL IN NUMBER, P_DATE_EXPR IN TIMESTAMP WITH TIME ZONE) RETURN TIMESTAMP WITH TIME ZONE;
Instead of calling the function by using PACK.X (SELECT PACK.X(...) FROM dual)
I want to able to call it using X only (SELECT X(...) FROM dual)
Is there any possible way ?
Thanks !That's a good question
Basically I'm converting MSSQLSERVER functions to oracle using an excellent provided ORACLE package (the SQL DEVELOPER generating it while migrating from MS to Oracle)
Now, In order to preserve code consistency, the developers wants to call these functions exactly the way the are calling it in MSSQLSERVER (for example SELECT DATEADD (...)) without the package name.
Off course its a very problematic demand, but it interest me theoretically, is it even possible. -
Tutorials needed on overloading functions
hi,
tutorials needed on overloading functions.
provide me with some good links which explains all type of possibilities of overloading.Some samples here :
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/subprograms.htm#i12352
Nicolas. -
Where can I find an example of teh overload functions for the "Createvariable"
I am trying to find a coding example of the overloads for the "CreateVariable" function in Measurement Studio. The goal is to define a variable type at creation time.
ThanksHi JohnnieM,
You can see the three overloads for the CreateVariable method in the help here: http://zone.ni.com/reference/en-XX/help/372636F-01/mstudiowebhelp/html/3c1ef3de/. I couldn't find an example snippet of code but if you wanted to explicity define the type you need to use CreateVariable(VariableCreationOptions) like this:
string processName = "myProcess";
string variableName = "myVariable";
ServerProcessInfo procInfo = ServerProcess.Create(processName, true);
VariableCreationOptions varOptions = new VariableCreationOptions(processName, variableName);
varOptions.VariableType = typeof(Double); //this is where you specify the type
ServerVariableInfo varInfo = procInfo.CreateVariable(varOptions);
Hope this helps!
Kevin -
Overloading functions and procedures
Let's imagine I have the following types :
create type T1 as object (...) ;
create type T2 under T2 (...) ;
Is it possible to define differents implementations of the same function, for instance :
create function F (t IN T1) begin ... end ;
create function F (t IN T2) begin ... end ;
It is one of the main features coming from the object technology, but it seems that Oracle9i doesn't implement it...Regis,
Method loading IS supported in Oracle9i. Please check out the documentation at http://206.204.21.139/otndoc/oracle9i/901_doc/appdev.901/a88878/adobjbas.htm#464358.
Regards,
Geoff
Let's imagine I have the following types :
create type T1 as object (...) ;
create type T2 under T2 (...) ;
Is it possible to define differents implementations of the same function, for instance :
create function F (t IN T1) begin ... end ;
create function F (t IN T2) begin ... end ;
It is one of the main features coming from the object technology, but it seems that Oracle9i doesn't implement it... -
I have the following two classes:
public class AClass implements Serializable;
public class RAClass extends AClass;
I have a remote EJB interface named Alarm where two methods in the remote interface look like this:
public long setAlarm(String usr, String pwd, AClass ac) throws RemoteException;
public long setAlarm(String usr, String pwd, RAClass rac) throws RemoteException;
Finally, in another class I have the following method:
public void writeAlarm(AClass ac) {
Alarm remoteObj;
//code to grab remote interface
System.out.println("class of ac "+ac.getClass().getName());
remoteObj.setAlarm(ac);
At runtime, the setAlarm call with the signature containing the base AClass is always called even when the ac object passed to writeAlarm is an object of type RACClass. I've even verified the type of the object with the println.
From reading the Java language specification, my understanding is that when the writeAlarm is called with an RACObject the setAlarm call with the RACClass in the signature should be the one called.
Is my reasoning wrong? Am I doing something else wrong?granted that EJB is kinda goofy... this kinda popped out at me...
public long setAlarm(String usr, String pwd, AClass ac) throws RemoteException;interface has two methodd with 3 parameter arguments...
but looking at the rest of the code posted, i only see this call to said methods...
remoteObj.setAlarm(ac);and that method only takes one argument...
which would indicate that there is a method that you declared that only takes one arguement ... and what type does it take ? my thinking is probably an AClass...
and that method would be able to accept both AClass and RAClass... being that RAClass " is a " AClass...
have fun... :-)
- MaxxDmg...
- " He who never sleeps... " -
Hello,
These ABAP commands have a different behavior in a report or in a user-exit.
For instance :
DATA: v_frac LIKE vbep-bmeng,
v_floor LIKE vbep-bmeng,
or (same results)
DATA: v_frac type p decimals 3,
v_floor type p decimals 3.
The code in my report ( ztest ) is :
vbep-bmeng = 1333 / 1000.
v_frac = FRAC( vbep-bmeng ).
v_floor = FLOOR( vbep-bmeng ).
I see, in debug mode:
v_frag set to 0.333 -> works fine
v_floor set to 1.000 -> works fine
Now in my User-exit (include MV45AFZZ), I put exactly the same code.
I see, in debug mode,
v_frag set to 0.000 -> ????
v_floor set to 1.333 -> ???
I don't understand why the results are different ?
In the Exit, the types P or Quant seem to be considered as Integer...
any idea ?
( R/3 ECC5, ABAP 6.40)
Thank you
Ramdanehi,
MV45AFZZ is an include of main program SAPMV45A. Whatever reason but the fixed point arithmetic is not turned on in this main program (an OSS issue?), I guess that is the reason, that the calculation fails.
hope this helps
ec -
Here i have a code mistake.i tried many times, how to solve this.
std::cerr<<"Genset COM..:"<<Gcom->ToString<<std::endl<<"GenSet ID ..:"<<Gid<<std::endl;On 4/18/2015 8:33 AM, "KrishnaPriya C" wrote:
Here i have a code mistake.i tried many times, how to solve this.
std::cerr<<"Genset COM..:"<<Gcom->ToString<<std::endl<<"GenSet ID ..:"<<Gid<<std::endl;
Most likely, you meant Gcom->ToString() (note the pair of parentheses).
Igor Tandetnik -
Bug in Apex 2.2.1.00.04 in overload call of function?
We are having custom table defined as:
CREATE TABLE HTMLDB_USERS (
ID INTEGER CONSTRAINT HTMLDB_USERS_ID_NN NOT NULL,
USERNAME VARCHAR2(64 BYTE) CONSTRAINT HTMLDB_USERS_USERNAME_NN NOT NULL,
desc htmldb_users Name Null? Type
ID NOT NULL NUMBER(38)
USERNAME NOT NULL VARCHAR2(64)
...Where ID is primary key and on USERNAME there is unique index defined.
In package we have two overload functions defined as:
FUNCTION update_password (
p_id IN HTMLDB_USERS.ID%TYPE
,p_password IN HTMLDB_USERS.PASSWORD%TYPE
) RETURN PLS_INTEGER;and later declared:
FUNCTION update_password (
p_username IN HTMLDB_USERS.USERNAME%TYPE
,p_password IN HTMLDB_USERS.PASSWORD%TYPE
) RETURN PLS_INTEGER;which should be correctly determined in call according different data types. In our page we had a call like:
:P102_STATE :=#OWNER#.pkg_auth.update_password(:P102_ID,:P102_NEW_PASSWORD2);
...Call was going to correct function (the one with ID in parameter).
In trace (have special pragma function for writing values to database) we get that passed values all the time was "-2", regarding that "P102_ID" was having correct INTEGER value ("3", "4", "7" etc...).
Interesting thing was that call with v('P102_ID') in function results OK!
When we place call by reference
p_id=>:P102_ID,p_password=>:P102_NEW_PASSWORD2);Then all was OK!
We are pointing to this bug because it may raise many problems to users....
select * from v$version;BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - ProductionHope this was worth of logging....and even this may not be treated as bug worth ow warning...Vikas,
all clear but that v('P102_ID') call is bothering me!
And other thing....I was debugging in first function (with number parameter)...and if API is making VARCHAR2 value, then in no circumstances first function (with number) cannot be called but only second one (with two VARCHAR2)...which was not called !!!!
To make more clear, create two function (in this order in package):
FUNCTION update_password (
p_id IN HTMLDB_USERS.ID%TYPE
,p_password IN HTMLDB_USERS.PASSWORD%TYPE
) RETURN PLS_INTEGER;
BEGIN
dbms_output.put_line(v('P102_ID'));
dbms_output.put_line('Number called function "'||to_char(p_id)|'"');
return null;
END;
FUNCTION update_password (
p_username IN HTMLDB_USERS.USERNAME%TYPE
,p_password IN HTMLDB_USERS.PASSWORD%TYPE
) RETURN PLS_INTEGER;
BEGIN
dbms_output.put_line(v('P102_ID'));
dbms_output.put_line('VARCHAR2 called function "'||p_username||'"');
return null;
END;and make a call like in my case.
This is most interesting of all! Intersting which function will be called!
Maybe this note helps someone to be mislead...
Message was edited by:
Funky -
Overloading a DATE function with TIMESTAMP to avoid "too many declarations"
CREATE OR REPLACE PACKAGE util
AS
FUNCTION yn (bool IN BOOLEAN)
RETURN CHAR;
FUNCTION is_same(a varchar2, b varchar2)
RETURN BOOLEAN;
FUNCTION is_same(a date, b date)
RETURN BOOLEAN;
/* Oracle's documentation says that you cannot overload subprograms
* that have the same type family for the arguments. But,
* apparently timestamp and date are in different type families,
* even though Oracle's documentation says they are in the same one.
* If we don't create a specific overloaded function for timestamp,
* and for timestamp with time zone, we get "too many declarations
* of is_same match" when we try to call is_same for timestamps.
FUNCTION is_same(a timestamp, b timestamp)
RETURN BOOLEAN;
FUNCTION is_same(a timestamp with time zone, b timestamp with time zone)
RETURN BOOLEAN;
/* These two do indeed cause problems, although there are no errors when we compile the package. Why no errors here? */
FUNCTION is_same(a integer, b integer) return boolean;
FUNCTION is_same(a real, b real) return boolean;
END util;
CREATE OR REPLACE PACKAGE BODY util
AS
NAME: yn
PURPOSE: pass in a boolean, get back a Y or N
FUNCTION yn (bool IN BOOLEAN)
RETURN CHAR
IS
BEGIN
IF bool
THEN
RETURN 'Y';
END IF;
RETURN 'N';
END yn;
NAME: is_same
PURPOSE: pass in two values, get back a boolean indicating whether they are
the same. Two nulls = true with this function.
FUNCTION is_same(a in varchar2, b in varchar2)
RETURN BOOLEAN
IS
bool boolean := false;
BEGIN
IF a IS NULL and b IS NULL THEN bool := true;
-- explicitly set this to false if exactly one arg is null
ELSIF a is NULL or b IS NULL then bool := false;
ELSE bool := a = b;
END IF;
RETURN bool;
END is_same;
FUNCTION is_same(a in date, b in date)
RETURN BOOLEAN
IS
bool boolean := false;
BEGIN
IF a IS NULL and b IS NULL THEN bool := true;
-- explicitly set this to false if exactly one arg is null
ELSIF a is NULL or b IS NULL then bool := false;
ELSE bool := a = b;
END IF;
RETURN bool;
END is_same;
FUNCTION is_same(a in timestamp, b in timestamp)
RETURN BOOLEAN
IS
bool boolean := false;
BEGIN
IF a IS NULL and b IS NULL THEN bool := true;
-- explicitly set this to false if exactly one arg is null
ELSIF a is NULL or b IS NULL then bool := false;
ELSE bool := a = b;
END IF;
RETURN bool;
END is_same;
FUNCTION is_same(a in timestamp with time zone, b in timestamp with time zone)
RETURN BOOLEAN
IS
bool boolean := false;
BEGIN
IF a IS NULL and b IS NULL THEN bool := true;
-- explicitly set this to false if exactly one arg is null
ELSIF a is NULL or b IS NULL then bool := false;
ELSE bool := a = b;
END IF;
RETURN bool;
END is_same;
/* Don't bother to fully implement these two, as they'll just cause errors at run time anyway */
FUNCTION is_same(a integer, b integer) return boolean is begin return false; end;
FUNCTION is_same(a real, b real) return boolean is begin return false; end;
END util;
declare
d1 date := timestamp '2011-02-15 13:14:15';
d2 date;
t timestamp := timestamp '2011-02-15 13:14:15';
t2 timestamp;
a varchar2(10);
n real := 1;
n2 real;
begin
dbms_output.put_line('dates');
dbms_output.put_line(util.yn(util.is_same(d2,d2) ));
dbms_output.put_line(util.yn(util.is_same(d1,d2) ));
dbms_output.put_line('timestamps'); -- why don't these throw exception?
dbms_output.put_line(util.yn(util.is_same(t2,t2) ));
dbms_output.put_line(util.yn(util.is_same(t,t2) ));
dbms_output.put_line('varchars');
dbms_output.put_line(util.yn(util.is_same(a,a)));
dbms_output.put_line(util.yn(util.is_same(a,'a')));
dbms_output.put_line('numbers');
-- dbms_output.put_line(util.yn(util.is_same(n,n2))); -- this would throw an exception
end;
/Originally, I had just the one function with VARCHAR2 arguments. This failed to work properly because when dates were passed in, the automatic conversion to VARCHAR2 was dropping the timestamp. So, I added a 2nd function with DATE arguments. Then I started getting "too many declarations of is_same exist" error when passing TIMESTAMPs. This made no sense to me, so even though Oracle's documentation says you cannot do it, I created a 3rd version of the function, to handle TIMESTAMPS explicitly. Surprisingly, it works fine. But then I noticed it didn't work with TIMESTAMP with TIME ZONEs. Hence, the fourth version of the function. Oracle's docs say that if your arguments are of the same type family, you cannot create an overloaded function, but as the example above shows, this is very wrong.
Lastly, just for grins, I created the two number functions, one with NUMBER, the other with REAL, and even these are allowed - they compile. But then at run time, it fails. I'm really confused.
Here is the apparently incorrect Oracle documentation on the matter: http://docs.oracle.com/cd/B12037_01/appdev.101/b10807/08_subs.htm (see overloading subprogram names), and here are the various types and their families: http://docs.oracle.com/cd/E11882_01/appdev.112/e17126/predefined.htm.
Edited by: hotwater on Jan 9, 2013 3:38 PM
Edited by: hotwater on Jan 9, 2013 3:46 PM>
So, I added a 2nd function with DATE arguments. Then I started getting "too many declarations of is_same exist" error when passing TIMESTAMPs. This made no sense to me
>
That is because when you pass a TIMESTAMP Oracle cannot determine whether to implicitly convert it to VARCHAR2 and use your first function or implicitly convert it to DATE and use your second function. Hence the 'too many declarations' exist error.
>
, so even though Oracle's documentation says you cannot do it, I created a 3rd version of the function, to handle TIMESTAMPS explicitly. Surprisingly, it works fine. But then I noticed it didn't work with TIMESTAMP with TIME ZONEs.
>
Possibly because of another 'too many declarations' error? Because now there would be THREE possible implicit conversions that could be done.
>
Hence, the fourth version of the function. Oracle's docs say that if your arguments are of the same type family, you cannot create an overloaded function, but as the example above shows, this is very wrong.
>
I think the documentation, for the 'date' family, is wrong as you suggest. For INTEGER and REAL the issue is that those are ANSI data types and are really the same Oracle datatype; they are more like 'aliases' than different datatypes.
See the SQL Language doc
>
ANSI, DB2, and SQL/DS Datatypes
SQL statements that create tables and clusters can also use ANSI datatypes and datatypes from the IBM products SQL/DS and DB2. Oracle recognizes the ANSI or IBM datatype name that differs from the Oracle Database datatype name. It converts the datatype to the equivalent Oracle datatype, records the Oracle datatype as the name of the column datatype, and stores the column data in the Oracle datatype based on the conversions shown in the tables that follow.
INTEGER
INT
SMALLINT
NUMBER(38)
FLOAT (Note b)
DOUBLE PRECISION (Note c)
REAL (Note d)
FLOAT(126)
FLOAT(126)
FLOAT(63) -
Overloading PL/SQl functions
HI Friends
I have an Issue .I need to overload a function in PL/SQL by changing the no of arguments(like C++ or java) .As per oracle doc, it is possible to do with in a PACKAGE . Can anyone suggest me How to do with out using package as a standalone function.Have anyone done that , then pl send me some tip or sample.
thanks and Happy programming
gopal VHi Gopal
Yes, you cannot do a standalone overloaded function, but as you rightly pointed out it can be done in package
- and that makes sense because the whole purpose of clubbing procedures and functions into package is to bring a
semblance of Object orientation into PL/SQL with function overloading (You still do not have operator overloding like in C++),
encapsulation etc.
Qurashi -
Function overloading on return types
consider following two overloaded functions
public int functionA(int a,int b);
public char functionA(int a,int b)and if i call them like this
int returnInt = functionA(a,b)
char returnChar = functionA(a,b)in this scenario which function to call can be decided depending on the
return type then why java don have overloading on the basis of return type ?Try it.
-
Overload/add functions in expression browser
Hi,
short question: Is it possible to add or overload functions in the expression browser? ( e.g. Str() )
Has anybody examples?
Cheers frankThis is not possible.
Allen P
NI
Maybe you are looking for
-
Black Screen on Windows 7 startup
Windows 7 desktop can not load after welcome screen appears just a black screen come and stuck a white mouse pointer works but nothing else. safe mode works and last known good configuration works whenever i start in above mentioned mode it works and
-
Practical need of G/L Account Code in SAP B1
Hi All, Is there any way to avoid the G/L Account Code in SAP B1? Is there any practical need of the G/L Account Codes when the Account Name itself is sufficient and unique in an organization? Thanx and Regards
-
Migrate DMS DIRS with originals from SAP R/3 4.6 C to ECC6
Dear All, I have a requirement to transfer all DMS master data with originals from SAP R/3 4.6C to ECC6. Presently the R/3 4.6 c has 3 instances with 3 different content servers. I have to transfer the master data of all 3 instances in one
-
Customer statement from trace in SAP
Hi, The business uses F.27 for customer statements and takes a printout.A customized form is created for the same. However I want to trace the form name in SAP? How can I do it in SAP?
-
Hello All, In WAD, when I use a command on a button to execute a planning function and bind it via DATA_PROVIDER_SELECTION I can choose the DP and the characteristic under that. But, when I click on input-help to select the Characteristic for plannin