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.
Similar Messages
-
Same functions with different return types in C++
Normally the following two functions would be considered the same:
int getdata ( char *s, int i )
long getdata ( char *s, int i )
Every other compiler we use would resolve both of these to the same function. In fact, it is not valid C++ code otherwise.
We include some 3rd party source in our build which sometimes messes with our typedefs causing this to happen. We have accounted for all of the function input types but never had a problem with the return types. I just installed Sun ONE Studio 8, Compiler Collection and it is generating two symbols in our libraries every time this occurs.
Is there a compiler flag I can use to stop it from doing this? I've got over 100 unresolved symbols and I'd rather not go and fix all of them if there is an easier way.Normally the following two functions would be
considered the same:
int getdata ( char *s, int i )
long getdata ( char *s, int i )Not at all. Types int and long are different types, even if they are implemented the same way.
Reference: C++ Standard, section 3.9.1 paragraph 10.
For example, you can define two functions
void foo(int);
void foo(long);
and they are distinct functions. The function that gets called depends on function overload resolution at the point of the call.
Overloaded functions must differ in the number or the type of at least one parameter. They cannot differ only in the return type. A program that declares or defines two functions that differ only in their return types is invalid and has undefined behavior. Reference: C++ Standard section 13.1, paragraph 2.
The usual way to implement overloaded functions is to encode the scope and the parameter types, and maybe the return type, and attach the encoding to the function name. This technique is known as "name mangling". The compiler generates the same mangled name for the declaration and definition of a given function, and different mangled names for different functions. The linker matches up the mangled names, and can tell you when no definition matches a reference.
Some compilers choose not to include the return type in the mangled name of a function. In that case, the declaration
int foo(char*);
will match the definition
long foo(char*) { ... }
But it will also match the definitions
myClass foo(char*) { ... }
double foo(char*) { ... }
You are unlikely to get good results from such a mismatch. For that reason, and because a pointer-to-function must encode the function return type, Sun C++ always encodes the function return type in the mangled name. (That is, we simplify things by not using different encodings for the same function type.)
If you built your code for a 64-bit platform, it would presumably link using your other compilers, but would fail in mysterious ways at run time. With the Sun compiler, you can't get into that mess.
To make your program valid, you will have to ensure your function declarations match their definitions. -
Calling an Oracle function of BOOLEAN return type
I am facing a situation, where I have defined an overloaded function in one package (2 variants) which both return a type BOOLAN value under Oracle 9i R1.
I am having trouble to setting up an CallableStatemnt to call one of this functions from Java. Whenever I set the parameter with a BIT or NUMBER data type, I get an exception with java.lang.boolean during my
callablestatement.setobject( index, parameter, OracleTypes.BIT );
or
callablestatement.setobject( index, parameter, OracleTypes.NUMBER );
I have no problem calling the function from SQLPlus, but doing so from Java raises the exception. I have found no exact match in OracleTypes or java.sql.Types for a BOOLEAN data type.
In your response do you mean to modify the Function to return a NUMBER instead of a BOOLEAN, or do you mean to set the parameter as Types.NUMBER in the calling java code?
Thanks,
Fedrolook at BOOLEAN type mapping using JPublisher
http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96658.pdf -
"Primitive Type Returned", when I try to configure the data return type.
I am basically following this tutorial, Getting started with ColdFusion and Flash Builder 4 beta, but instead of using the database provided, I am using SQL Server 2008. I am now stuck on the part titled, "Configuring the data return type". In step 5 of this section, I submit my credentials and then I get a popup titled:
Primitive Type Returned
The operation returned a response of the type "Object".
You may either update server code to fix the returned data or Click OK to set "Object" as the return type of this operation.
I am not sure if "server code" would be my database and/or the Coldfusion code that was provided in this tutorial. I am thinking that its the former, however I am new to both technologies. Would anyone know why FlashBuilder will not strong type this data for me?Hi,
Thanks for your feedback!
The server code here means the ColdFusion code provided in the tutorial.
The "Configure return type" step is performed to change the return type of the function.
If you notice after importing the CFC in the Flash Builder the return type of getAllData was Object but with this step you are trying to change it to a Strong Type.
So context click on the getAllData function,select 'Configure return type', enter "EmployeeSalesData" click NEXT , enter valid RDS credentials in the security dialog and click FINISH.
This should have ideally set your return type to "EmployeeSalesData"(Strong type).
Also if you are extremely new to this i suggest you to pick up a pre-release build of Flash Builder which has a COOL feature which can help you get started pretty fast and simplify most of these workflows.
To avail for the pre-release build please send a mail to [email protected]
Hope this helps!
Thanks,
Balaji
http://balajisridhar.wordpress.com -
Covariant return types - JLS to support but JVM will not?
Could you please confirm the following? My understanding is that covariant return types will be supported by the JLS but the JVM will know nothing about them. That is, the invokevirtual instruction will not change to support covariant return types but rather the compiler will use bridge methods to simulate support. Is this correct?
Right: but is there support for this in 1.5?
javac -verbose -source 1.5 -target 1.5 *java
was run on a .java file with the following methods and it failed "getX already defined"
public Integer getX() {
return(null);
public String getX() {
return(null);
The above would be overloading by return type and fails to compile.
================
class A {
Exception f() {}
class B extends A {
BindException f() {} // overload or override?
The above would be covariant returns and works just fine right? -
Return type Boolean From Oracle Function
1. How do I get a return type of Boolean from Oracle function in Java?
2. I have a function fx overloaded in Oracle (8 variances) and I have trouble getting the right one in Java. Is 8 too high a figure or Java does not support calling overloaded functions or what?
Thanks for any help.I am facing a similar situation, where I have defined an overloaded function in one package (2 variants) which both return a type BOOLAN value.
I am having trouble to setting up an CallableStatemnt to call one of this functions from Java. Whenever I set the parameter with a BIT or NUMBER data type, I get an exception with java.lang.boolean during my
callablestatement.setobject( indez, parameter, OracleTypes.BIT );
or
callablestatement.setobject( indez, parameter, OracleTypes.NUMBER );
I have no problem calling the function from SQLPlus, but doing so from Java raises the exception. I have found no exact match in OracleTypes or java.sql.Types for a BOOLEAN data type.
In your response do you mean to modify the Function to return a NUMBER instead of a BOOLEAN, or do you mean to set the parameter as Types.NUMBER in the calling java code?
Thanks,
Fedro -
I am currently testing our website with CF11. It is currently working with CF8 however after migrating it to a new server running CF11 I have encountered the following error.
The value returned from the load function is not of type numeric.
The error occurred in
D:/Applications/CFusion/CustomTags/nec/com/objects/address.cfc: line 263
Called from D:/Applications/CFusion/CustomTags/nec/com/objects/contact.cfc: line 331
Called from D:/Applications/CFusion/CustomTags/nec/com/objects/user.cfc: line 510
Called from D:/Applications/CFusion/CustomTags/nec/com/objects/user.cfc: line 1675
Called from D:/website/NECPhase2/action.validate.cfm: line 54
261 : <cfif isNumeric(get.idCountry)>
262 : <cfset rc = this.objCountry.setID(get.idCountry)>
263 : <cfset rc = this.objCountry.load()>
264 : </cfif>
265 : <cfset this.sPostcode = get.sPostcode>
Have there been any changes between CF8 and CF11 that could cause this error?
Does anyone have ideas?This is the code in file object file country.cfc (nec.com.objects.country):
<cfcomponent displayname="Country object" hint="This is a Country object, it allows you to access and set values in the Country.">
<!---
// Construct this object
--->
<cfset this.objFunctions = CreateObject( 'component', 'nec.com.system.functions' )>
<cfscript>
this.idCountryID = 0;
this.sCountryName = "";
this.sISOCode = "";
this.sDHLCode = "";
this.iErrorID = "";
</cfscript>
<!---
// The following functions are the setters and getters. offering us a better way to get
// at the contents of the object
--->
<!---
// Getters
--->
<cffunction name="getID" displayname="Get ID" returntype="numeric" output="false" hint="This returns the ID of the current item.">
<cfreturn this.idCountryID>
</cffunction>
<cffunction name="getsCountryName" displayname="Get sCountryName" returntype="string" output="false" hint="This gets the sCountryName value of this item.">
<cfreturn this.sCountryName>
</cffunction>
<cffunction name="getsISOCode" displayname="Get sISOCode" returntype="string" output="false" hint="This gets the sISOCode value of this item.">
<cfreturn this.sISOCode>
</cffunction>
<cffunction name="getsDHLCode" displayname="Get sDHLCode" returntype="string" output="false" hint="This gets the sDHLCode value of this item.">
<cfreturn this.sDHLCode>
</cffunction>
<cffunction name="iError" displayname="Get iError" returntype="numeric" output="false" hint="This returns the iError of the current item.">
<cfreturn this.iError>
</cffunction>
<!---
// Setters
--->
<cffunction name="setID" displayname="Set ID" returntype="boolean" output="false" hint="This sets the ID value of this item.">
<cfargument name="idCountryID" required="true" type="numeric" displayname="ID" hint="The ID to use.">
<cfset this.idCountryID = arguments.idCountryID>
<cfreturn true>
</cffunction>
<cffunction name="setsCountryName" displayname="Set sCountryName" returntype="boolean" output="false" hint="This sets the sCountryName value of this item.">
<cfargument name="sCountryName" required="true" type="string" displayname="sCountryName" hint="The sCountryName to use.">
<cfset this.sCountryName = arguments.sCountryName>
<cfreturn true>
</cffunction>
<cffunction name="setsISOCode" displayname="Set sISOCode" returntype="boolean" output="false" hint="This sets the sISOCode value of this item.">
<cfargument name="sISOCode" required="true" type="string" displayname="sISOCode" hint="The sISOCode to use.">
<cfset this.sISOCode = arguments.sISOCode>
<cfreturn true>
</cffunction>
<cffunction name="setsDHLCode" displayname="Set sDHLCode" returntype="boolean" output="false" hint="This sets the sDHLCode value of this item.">
<cfargument name="sDHLCode" required="true" type="string" displayname="sDHLCode" hint="The sDHLCode to use.">
<cfset this.sDHLCode = arguments.sDHLCode>
<cfreturn true>
</cffunction>
<!---
// Clear, to empty out the contents of this object
--->
<cffunction name="clear" displayname="Clear items Details" returntype="boolean" output="false" hint="Clears out all of the items details.">
<cfscript>
this.sCountryName = "";
this.sISOCode = "";
this.sDHLCode = "";
this.iErrorID = "";
</cfscript>
<cfreturn true>
</cffunction>
<!---
// The following functions deal with the load, save and deleting of objects
--->
<!---
// Load
--->
<cffunction name="load" displayname="Load items details" returntype="numeric" output="false" hint="This loads in all the information about an item.">
<cfset rc = this.clear()>
<!---
// First of all we need to get the name of the data source we are going to be using
--->
<cfscript>
objDS = CreateObject("component","nec.com.system.settings");
sDatasource = objDS.getDatasource();
</cfscript>
<!---
// Check to see if it exists
--->
<cftry>
<cfquery name="checkID" datasource="#sDatasource#">
SELECT idCountryID
FROM tblCountry
WHERE idCountryID = #this.idCountryID#
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("load: checkID: '#this.idCountryID#' #cfcatch.detail#");
</cfscript>
<cfset this.iErrorID = iErrorID>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<cfif not checkID.recordCount>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
if(isDefined("session.afr")){
whichOne = "#session.afr.getsAFRNumber()#";
} else {
whichOne = "";
iErrorID = objError.addError("A Country with that id doesn't exists.[#this.idCountryID#][#whichOne#]");
</cfscript>
<cfset this.iErrorID = iErrorID>
<cfreturn iErrorID>
</cfif>
<!---
// If we got past all then then load in the details
--->
<cftry>
<cfquery name="get" datasource="#sDatasource#">
SELECT idCountryID, RTRIM(sCountryName) as sCountryName, RTRIM(sISOCode) as sISOCode, RTRIM(sDHLCode) as sDHLCode
FROM tblCountry
WHERE idCountryID = #this.idCountryID#
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("load: get: #cfcatch.detail#");
</cfscript>
<cfset this.iErrorID = iErrorID>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<cfset this.idCountryID = get.idCountryID>
<cfset this.sCountryName = get.sCountryName>
<cfset this.sISOCode = get.sISOCode>
<cfset this.sDHLCode = get.sDHLCode>
<cfset this.iErrorID = "">
<cfreturn true>
</cffunction>
<!---
// Save
--->
<cffunction name="save" displayname="Save items Details" returntype="numeric" output="false" hint="Saves (to some source) the current details for the ID of the item.">
<!---
// First of all we need to get the name of the data source we are going to be using
--->
<cfscript>
objDS = CreateObject("component","nec.com.system.settings");
sDatasource = objDS.getDatasource();
</cfscript>
<!---
// Now check to see if ithat ID exists
--->
<cftry>
<cfquery name="checkID" datasource="#sDatasource#">
SELECT idCountryID
FROM tblCountry
WHERE idCountryID = #this.idCountryID#
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("save: checkID: #cfcatch.detail#");
</cfscript>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<!---
// If it doesn't exist, then add the record, otherwise update the record
--->
<cfif not checkID.recordCount>
<cfreturn this.add()>
<cfelse>
<cfreturn this.update()>
</cfif>
</cffunction>
<!---
// Add
--->
<cffunction name="add" displayname="Add Country" returntype="numeric" output="false" hint="This adds a Country.">
<!---
// Check to see if that a different item isn't already using the same unique details
--->
<cftry>
<cfquery name="checkUnique" datasource="#sDatasource#">
SELECT idCountryID
FROM tblCountry
WHERE sCountryName = '#this.objFunctions.scrubText(this.sCountryName)#'
OR sISOCOde = '#this.objFunctions.scrubText(this.sISOcode)#'
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("add: checkUnique: #cfcatch.detail#");
</cfscript>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<cfif checkUnique.recordCount>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("A Country with that name or ISO code already exists. idCountryID=#checkUnique.idCountryID#");
</cfscript>
<cfreturn iErrorID>
</cfif>
<cftry>
<cfquery name="add" datasource="#sDatasource#">
SET nocount on
INSERT INTO tblCountry(sCountryName, sISOCode, sDHLCode)
VALUES('#this.objFunctions.scrubText(this.sCountryName)#','#this.objFunctions.scrubText(t his.sISOCode)#','#this.objFunctions.scrubText(this.sDHLCode)#')
SELECT @@identity as autoID
SET nocount off
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("add: add: #cfcatch.detail#");
</cfscript>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<cfreturn add.autoID>
</cffunction>
<!---
// Update
--->
<cffunction name="update" displayname="Update Country" returntype="numeric" output="false" hint="This updates a Country record.">
<!---
// Check to see if that a different item isn't already using the same unique details
--->
<cftry>
<cfquery name="checkUnique" datasource="#sDatasource#">
SELECT idCountryID
FROM tblCountry
WHERE (sCountryName = '#this.objFunctions.scrubText(this.sCountryName)#'
OR sISOCOde = '#this.objFunctions.scrubText(this.sISOcode)#')
AND idCountryID <> #this.idCountryID#
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("update: checkUnique: #cfcatch.detail#");
</cfscript>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<cfif checkUnique.recordCount>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("Another Country with that name already exists. idCountryID=#checkUnique.idCountryID#");
</cfscript>
<cfreturn iErrorID>
</cfif>
<!---
// Attempt to update the record to the datasource
// if this fails for any reason then we submit an error message
// to the error component and return the ID of the error
--->
<cftry>
<cfquery name="update" datasource="#sDatasource#">
UPDATE tblCountry
SET sCountryName = '#this.objFunctions.scrubText(this.sCountryName)#',
sISOCode = '#this.objFunctions.scrubText(this.sISOCode)#',
sDHLCode = '#this.objFunctions.scrubText(this.sDHLCode)#'
WHERE idCountryID = #this.idCountryID#
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("update: update: #cfcatch.detail#");
</cfscript>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<cfreturn this.idCountryID>
</cffunction>
<!---
// Delete
--->
<cffunction name="delete" displayname="Delete Country" returntype="numeric" output="false" hint="This deletes a Country record.">
<!---
// First of all we need to get the name of the data source we are going to be using
--->
<cfscript>
objDS = CreateObject("component","nec.com.system.settings");
sDatasource = objDS.getDatasource();
</cfscript>
<!---
// Now check to see if ithat ID exists
--->
<cftry>
<cfquery name="checkID" datasource="#sDatasource#">
SELECT idCountryID
FROM tblCountry
WHERE idCountryID = #this.idCountryID#
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("delete: checkID: #cfcatch.detail#");
</cfscript>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<cfif not checkID.recordCount>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("A Country with that id doesn't exists, delete failed.");
</cfscript>
<cfreturn iErrorID>
</cfif>
<!---
// Now check to see if there are any dependancies, if so we can't delete the item
--->
<cftry>
<cfquery name="checkDependancies" datasource="#sDatasource#">
SELECT idCountry
FROM tblAddress
WHERE idCountry = #this.idCountryID#
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("delete: checkDependancies: idCountry: #cfcatch.detail#");
</cfscript>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<cfif checkDependancies.recordCount>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("That Country is being used by an address, delete failed.");
</cfscript>
<cfreturn iErrorID>
</cfif>
<!---
// Now attempt to remove the record.
// if this fails for any reason then we submit an error message
// to the error component and return the ID of the error
--->
<cftry>
<cfquery name="delete" datasource="#sDatasource#">
DELETE FROM tblCountry
WHERE idCountryID = #this.idCountryID#
</cfquery>
<cfcatch>
<cfscript>
objError = CreateObject("component","nec.com.system.errors");
iErrorID = objError.addError("delete: delete: #cfcatch.detail#");
</cfscript>
<cfreturn iErrorID>
</cfcatch>
</cftry>
<cfreturn this.idCountryID>
</cffunction>
</cfcomponent> -
Problem when calling a return type BOOLEAN SQL Function in a package
Hi All,
I am having problem when trying to call a SQL function in a package with return type BOOLEAN
The SQL function signature is as follows
CREATE OR REPLACE PACKAGE RMSOWNER.ORDER_ATTRIB_SQL ****
FUNCTION GET_PO_TYPE_DESC(O_error_message IN OUT VARCHAR2,
I_PO_TYPE IN VARCHAR2,
O_PO_TYPE_DESC IN OUT VARCHAR2)
RETURN BOOLEAN;
Following is my java code
+CallableStatement cs3 = conn.prepareCall("{?=call ORDER_ATTRIB_SQL.GET_PO_TYPE_DESC(?,?,?)}");+
+cs3.registerOutParameter(1, java.sql.Types.BOOLEAN);+
+cs3.registerOutParameter(2, java.sql.Types.VARCHAR);+
+cs3.registerOutParameter(4, java.sql.Types.VARCHAR);+
+cs3.setString(2, "");+
+cs3.setString(3, "ST");+
+cs3.setString(4, "");+
+ResultSet rs3 = cs3.executeQuery();+
I get the following exception, i tried changing the sql type(registerOutParameter) from boolean to bit but i still getting this exception.
But when i call any other functions with return type other than boolean they work perfectly fine.
Please can anyone help me fix this issue, i am not sure if its anything to do with vendor JDBC classes?
+java.sql.SQLException: ORA-06550: line 1, column 13:+
+PLS-00382: expression is of wrong type+
+ORA-06550: line 1, column 7:+
+PL/SQL: Statement ignored+
+ at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)+
+ at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)+
+ at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)+
+ at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)+
+ at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:215)+
+ at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:954)+
+ at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)+
+ at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)+
+ at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3422)+
+ at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4394)+
#####Hello People!
There is another workaround!!
See the example below:
private String callBooleanAPi(String tableName,String apikey,String dtInicio,String dtFim,String comando) throws SQLException {
CallableStatement cs = null;
String call = "";
String retorno = null;
try {
if(comando.equalsIgnoreCase("INSERT")){
call = "declare x BOOLEAN; y varchar2(2);begin x :=PKG.INSERT(?,?,?,?,?); if x then y := 'S'; else y :='N'; end if; ? := y;end;";
} else if(comando.equalsIgnoreCase("UPDATE")){
call = "declare x BOOLEAN; y varchar2(2);begin x := PKG.UPDATE(?,?,?,?,?); if x then y := 'S'; else y :='N'; end if; ? := y;end;";
} else if(comando.equalsIgnoreCase("DELETE")){
call = "declare x BOOLEAN; y varchar2(2);begin x := PKG.DELETE(?,?,?,?,?); if x then y := 'S'; else y :='N'; end if; ? := y;end;";
cs = conn.prepareCall(call);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat sdfToSqlDate = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date dataInicialVigencia =null;
java.util.Date dataFinalVigencia = null;
Date dtInicialFormatada =null;
Date dtFinalFormatada = null;
if(dtInicio != null && !dtInicio.equals("")){
dataInicialVigencia = sdf.parse(dtInicio);
dtInicio =sdfToSqlDate.format(dataInicialVigencia);
dtInicialFormatada = Date.valueOf(dtInicio);
if(dtFim != null && !dtFim.equals("")){
dataFinalVigencia = sdf.parse(dtFim);
dtFim =sdfToSqlDate.format(dataFinalVigencia);
dtFinalFormatada = Date.valueOf(dtFim);
cs.setString(1, tableName);
cs.setString(2, apikey);
cs.setDate(3, dtInicialFormatada );
cs.setDate(4, dtFinalFormatada );
cs.registerOutParameter(5, java.sql.Types.VARCHAR);
cs.registerOutParameter(6, java.sql.Types.VARCHAR );
cs.execute();
retorno = cs.getString(6);
System.out.println( cs.getString(5));
} catch(SQLException e){
throw new SQLException("An SQL error ocurred while calling the API COR_VIGENCIA: " + e);
} catch(Exception e){
Debug.logger.error( "Error calculating order: " + id, e );
} finally {
if (cs != null) {
cs.close();
cs = null;
return retorno;
As you can see the CallableStatement class acepts PL/SQl blocks.
Best Regards. -
Function with return type boolean
I have created a function with return type boolean as:
CREATE OR REPLACE FUNCTION fn RETURN BOOLEAN
AS
exp EXCEPTION;
BEGIN
return TRUE;
EXCEPTION
when OTHERS then RAISE exp;
END;
FUNCTION fn compiledThen I was trying to call this function into dbms_output.put_line procedure, I got this error:
EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'Can someone please help me understand, why this happened?
Is this because of boolean return type?952040 wrote:
I have created a function with return type boolean as:
Then I was trying to call this function into dbms_output.put_line procedure, I got this error:
EXECUTE DBMS_OUTPUT.PUT_LINE(fn);
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
What is the parameter signature for DBMS_OUTPUT.put_line() ?
Is is string - as detailed in Oracle® Database PL/SQL Packages and Types Reference guide.
So how can you pass a boolean data type as parameter value, when the parameter's data type is string?
PL/SQL supports implicit data conversion. So you can for example pass a number or date value to DBMS_OUTPUT.put_line() - and the PL/SQL engine automatically (and implicitly) converts that (using the TO_CHAR() functions) to a string.
However, the TO_CHAR() parameter signature supports number and date - not boolean. It cannot convert a boolean value into a string.
So passing a boolean value means the implicit conversion fails - and results in the above error.
To make it work, you need to perform an explicit conversion. As as a data type conversion function from boolean to string is not available, you need to write a user defined function. E.g.
SQL> create or replace function BoolToChar( b boolean ) return varchar2 is
2 begin
3 case
4 when b then return( 'TRUE' );
5 when not b then return( 'FALSE' );
6 else
7 return( null );
8 end case;
9 end;
10 /
Function created.
SQL>
SQL> exec DBMS_OUTPUT.put_line( 'Flag is '||BoolToChar(true) );
Flag is TRUE
PL/SQL procedure successfully completed -
How to PL/SQL Function returns type
Hello,
I need to create a function, which is returning a list of ID's, which is stored in a type T_IDs, something like:
function search(searchstring in varchar2) return T_IDs
I have a little problem with filling the type inside the function body using a select statement like
select id from table where text like searchstring;
which is selecting a list of ids matching the where-clause. Is it possible to use select into or should I go for another mechanism?
Thanks for any ideas.CoBy wrote:
Yes, no problem, this is the code I am testing on
create table texttabelle(
id number(10),
dokument clob
+)+
+/+
create sequence seq_texttabelle
+/+
insert into texttabelle values (seq_texttabelle.nextval, 'A-Partei gewinnt Wahl in Hansestadt');
insert into texttabelle values (seq_texttabelle.nextval, 'Terror in Nahost: Kriminalität steigt immer weiter an');
insert into texttabelle values (seq_texttabelle.nextval, 'Wirtschaft: Erneuter Gewinnzuwachs in diesem Jahr');
insert into texttabelle values (seq_texttabelle.nextval, 'Olympia rückt näher: Der Fackellauf ist in vollem Gange');
insert into texttabelle values (seq_texttabelle.nextval, 'Wer wird US-Präsident? Obama und Clinton machen Wahlkampf');
insert into texttabelle values (seq_texttabelle.nextval, 'Papst bestürzt über jüngsten Skandal!');
insert into texttabelle values (seq_texttabelle.nextval, 'Wahlkampf in den USA geht weiter: Clinton und Obama LIVE zu sehen');
insert into texttabelle values (seq_texttabelle.nextval, 'Software-Kenntnisse werden immer wichtiger');
insert into texttabelle values (seq_texttabelle.nextval, 'Umfrage: Alle wollen mehr Geld!');
insert into texttabelle values (seq_texttabelle.nextval, 'Der Papst liest seine erste Messe in den USA!');
commit
+/+
create index idx_text on texttabelle (dokument)
indextype is ctxsys.context
+/+
CREATE OR REPLACE type T1 as object (
numero number(2)
+);+
+/+
The desired function has following specification:
CREATE OR REPLACE FUNCTION fkt_search (search_str IN VARCHAR2) RETURN T1;
The select statement I would like to use is:
SELECT id
FROM texttabelle
WHERE contains (dokument, search_str) > 0;
As I said, I cannot construct the correct select into - statement to fill the T1 with the result ID's from above.
ThanksYour problem is that you are returning a single object from your function, not a collection of them. -
Error 136 Functions that can be compossed must declare a return type
Hello,
I have downloaded the EF Final Release driver and Im working with Oracle 11g express.
I have the following Procedure:
PROCEDURE ProductosPedido(
Datos Out SYS_RefCursor) IS
BEGIN
OPEN Datos FOR
SELECT Nombre,
TO_NUMBER(Precio * (SELECT SUM(unidades)
FROM DETALLES_PEDIDO
WHERE PRODUCTO = PRODUCTO.ID)) Importe
FROM PRODUCTO;
END;
And the following config section:
<oracle.dataaccess.client>
<settings>
<add name="System.Productospedido.RefCursor.Datos" value="implicitRefCursor bindinfo='mode=Output'"/>
<add name="System.Productospedido.RefCursorMetaData.Datos.Column.0" value="implicitRefCursor metadata='ColumnName=Nombre;BaseColumnName=Nombre;BaseSchemaName=System;BaseTableName=Producto;NativeDataType=nvarchar2;ProviderType=NVarchar2;DataType=System.String;ColumnSize=50;AllowDBNull=true;IsKey=false'" />
<add name="System.Productospedido.RefCursorMetaData.Datos.Column.1" value="implicitRefCursor metadata='ColumnName=Importe;NativeDataType=number;ProviderType=Decimal;DataType=System.Decimal;AllowDBNull=false;IsKey=false;ColumnSize=8'" />
</settings>
</oracle.dataaccess.client>
I have imported succesfully in my EF Model, but when I try to consume the Procedure it gives me Error 136 Functions that can be compossed must declare a return type
Any solutions?
Thanks and best regards!A stored procedure does not have a ReturnType, therefore IsComposable="false" and it cannot be used in LINQ queries.
This limitation is imposed by EF and not by ODP.
You may want to create a stored function which has a ReturnType ref cursor, and include this stored function into your model. Then, under the same namespace, you create a class with a "stub" method/function and use EdmFunction() to map this stub to the stored function. For example,
class myFuncClass
[EdmFunction("Model.Store", "MY_STORED_FUNC_1")]
public static <your_complex_type_or_DbDataRecord> MyFunc_1(int? column1, ...)
throw new NotSupportedException("Direct calls are not supported");
You should be able to call myFuncClass.MyFunc_1(x) in your LINQ query. Your stored function MY_STORED_FUNC_1 will be called in the generated query. -
How to call a function having OBJECT type as Return type
Hi,
I've the following function returning OBJECT type.
Pease advice me how to call this function
CREATE OR REPLACE TYPE GET_EMP_OBJ is object
( emp_name varchar2(50) ,
mgr_id number,
dept_id number
CREATE OR REPLACE FUNCTION get_emp(P_emp_no NUMBER )
RETURN GET_EMP_OBJ IS
t_emp_info GET_EMP_OBJ ;
v_ename EMP.ename%TYPE;
v_mgr EMP.mgr%TYPE ;
v_deptno EMP.deptno%TYPE;
v_ename1 EMP.ename%TYPE;
v_mgr1 EMP.mgr%TYPE ;
v_deptno1 EMP.deptno%TYPE;
BEGIN
FOR rec IN ( SELECT ename , mgr , deptno
FROM emp )
LOOP
v_ename := rec.ename ;
v_ename1 := v_ename1||'|'||v_ename ;
v_mgr := rec.mgr ;
v_mgr1 := v_mgr1||'|'||v_mgr ;
v_deptno:= rec.deptno;
v_deptno1 := v_deptno1||'|'||v_deptno ;
END LOOP ;
t_emp_info := GET_EMP_OBJ (v_ename,v_mgr,v_deptno ) ;
RETURN t_emp_info ;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.put_line ('Error'||SQLCODE||','||SQLERRM ) ;
END;The above function got created successfully.
And i'm confused how to call this functions. I tried like below but didn't work
DECLARE
t_emp_info_1 GET_EMP_OBJ ;
BEGIN
t_emp_info_1 := get_emp(7566) ;
for i in 1..t_emp_info_1.COUNT
LOOP
DBMS_OUTPUT.put_line ('Values are'||i.emp_name ) ;
END LOOP;
END;SQL> CREATE OR REPLACE TYPE GET_EMP_OBJ is object
2 ( emp_name varchar2(50) ,
3 mgr_id number,
4 dept_id number
5 );
6 /
Type created.
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE FUNCTION get_emp(empno NUMBER )
2 RETURN GET_EMP_OBJ IS
3 t_emp_info GET_EMP_OBJ ;
4 BEGIN
5 begin
6 select get_emp_obj(ename, mgr, deptno) into t_emp_info
7 from emp
8 where empno = get_emp.empno;
9 exception
10 when no_data_found then
11 t_emp_info := new get_emp_obj(null,null,null);
12 end;
13 return t_emp_info;
14* END;
SQL> /
Function created.
SQL> set serverout on
SQL>
SQL> declare
2 t_emp_info GET_EMP_OBJ ;
3 BEGIN
4 t_emp_info := get_emp(7566);
5 DBMS_OUTPUT.put_line ('Values are: '||t_emp_info.emp_name||', '||t_emp_info.mgr_id||', '||t_emp_info.dept_id);
6 END;
7 /
Values are: JONES, 7839, 20
PL/SQL procedure successfully completed.
SQL> -
Prior, Next, Shift functions return type?
I can not point out what is the return type of these functions? numeric value or member?
And if they return a member would this fomula be valid (i need to take avg value of march and june):
avgppl = @avgrange("HRsummary" -> "territory",@list(@currmbr("YearTotal"),@shift(@currmbr("YearTotal"),-3)))
Thanks in advance!just use simple arithmetic combined with other functions
e.g.
If you want sum of base time periods underneath a summary time period, and make the formula generic to work on base time periods:
@SUMRANGE(@CURRMBR(Account),@Relative(@CURRMBR(Period),0))/@COUNT(SKIPNONE,@Relative(@CURRMBR(Period),0))
or, instead if you want the quarter averages at base time periods...
@SUMRANGE(@CURRMBR(Account),@Relative(@Relative(@CURRMBR(Period),-1),0))/@COUNT(SKIPNONE,@Relative(@Relative(@CURRMBR(Period),-1),0)) -
OracleDbType for function OBJECT return type
Hi all,
I inherited an oracle function that has an object as a return type:
create or replace TYPE OBJECTPATH IS OBJECT (OBJECTID NUMBER);
create or replace TYPE OBJECTPATH_TAB AS TABLE OF OBJECTPATH;
create or replace FUNCTION GETOBJECTINPATH ( pobjectid in NUMBER, role1 varchar2, role2 varchar2 ) RETURN OBJECTPATH_TAB
IS
v_tmp_tab OBJECTPATH_TAB:=OBJECTPATH_TAB();
parentid NUMBER;
rowno INTEGER;
BEGIN
rowno:=0;
parentid:=pobjectid;
loop
select objectid into parentid from dual left join (select ro2.objectid from relationshipobject ro1, relationshipobject ro2
where ro1.role=role1 and ro2.role=role2 and ro1.relationshipid=ro2.relationshipid and ro1.objectid=parentid)
on 1=1;
if parentid is null then
exit;
end if;
v_tmp_tab.extend;
rowno:=rowno1;+
v_tmp_tab(rowno) := OBJECTPATH(parentid);
end loop;
RETURN v_tmp_tab;
END;
On my application side, I am trying to run this function and retrieve the return value with ODP.NET as below. However, I am stumped when I need to supply an OracleDbType for the function return type.
1. What is the OracleDbType I should use for the return type? I read that there used to be support for OracleDbType.Object, but it seems like it is now not supported. I am using ODP.NET 11g. Am I getting the situation correct?
2. If retrieving an object return type is not as straightforward as setting the parameters (as what I have done below), what is the workaround to achieve it?
OracleCommand runGetPObjectInPathCmd = new OracleCommand("GETOBJECTINPATH", conn);
runGetPObjectInPathCmd.CommandType = CommandType.StoredProcedure;
runGetPObjectInPathCmd.Parameters.Add(new OracleParameter("pobjectid", OracleDbType.Decimal)).Value = pobjectId;
runGetPObjectInPathCmd.Parameters["pobjectid"].Direction = ParameterDirection.Input;
runGetPObjectInPathCmd.Parameters.Add(new OracleParameter("role1", OracleDbType.Varchar2, 255)).Value = role1;
runGetPObjectInPathCmd.Parameters["role1"].Direction = ParameterDirection.Input;
runGetPObjectInPathCmd.Parameters.Add(new OracleParameter("role2", OracleDbType.Varchar2, 255)).Value = role2;
runGetPObjectInPathCmd.Parameters["role2"].Direction = ParameterDirection.Input;
runGetPObjectInPathCmd.Parameters.Add("OBJECTPATH_TAB", OracleDbType.Decimal); // this is not correct as the return type is not a NUMBER
runGetPObjectInPathCmd.Parameters["OBJECTPATH_TAB"].Direction = ParameterDirection.ReturnValue;
runGetPObjectInPathCmd.ExecuteNonQuery();
Thanks in advance for any help and would greatly appreciate it.Hi Greg,
Thanks for your reply. I am not exactly sure whether I am using 11.1.0.6.21. The Oracle.DataAccess.dll I see under my \ODP.NET\bin\2.x directory is of Assembly/Product Version 2.111.6.0 - is this version 11.1.0.6.21? I also do not have the samples directory. Am I working on a wrong version? Thanks for your patience as I am really new to this and appreciate your guidance. -
How to execute a function returning type in oracle
hi
i want to execute a function which is returning table from oracle prompt.
i have created type in order to return table from function.
/*creating type
CREATE OR REPLACE TYPE U_VOC.t_in_list_tab AS OBJECT (i_group NUMBER ,
i_company number,
i_estab number
NOT FINAL ;
CREATE OR REPLACE TYPE U_VOC.t_in_list_tab_type
AS TABLE OF U_VOC.t_in_list_tab;
/*function */
CREATE OR REPLACE FUNCTION FU_VOC_S_VEHICLES(pi_group number,
pi_company number,
pi_estab number
RETURN t_in_list_tab
AS
v_nb_idvehicle U_REF.V_REF_VEHICLES.NB_IDVEHICLE%type ;
v_vc_reference U_REF.V_REF_VEHICLES.VC_REFERENCE%type ;
v_vc_licenceplate U_REF.V_REF_VEHICLES.VC_LICENCEPLATE%type ;
l_tab t_in_list_tab := t_in_list_tab( pi_group ,pi_company, pi_estab );
BEGIN
SELECT V_REF_VEHICLES.NB_IDVEHICLE,
V_REF_VEHICLES.VC_REFERENCE,
V_REF_VEHICLES.VC_LICENCEPLATE
INTO V_NB_IDVEHICLE,
V_VC_REFERENCE,
V_VC_LICENCEPLATE
FROM U_REF.V_REF_VEHICLES
WHERE V_REF_VEHICLES.NB_IDGROUP = pi_group
AND V_REF_VEHICLES.NB_IDCOMPANY = pi_company
AND V_REF_VEHICLES.NB_ESTABL = pi_estab;
RETURN l_tab;
END;
please help
Thank in advance
SandySandy,
I have a series of examples on this issue in my demo application. See this one:
http://htmldb.oracle.com/pls/otn/f?p=31517:146
You will basicaly need to write it like this:
CREATE OR REPLACE TYPE u_voc.t_in_list_tab AS OBJECT (
i_group NUMBER,
i_company NUMBER,
i_estab NUMBER
CREATE OR REPLACE TYPE u_voc.t_in_list_tab_type AS TABLE OF u_voc.t_in_list_tab;
CREATE OR REPLACE FUNCTION fu_voc_s_vehicles (
pi_group NUMBER,
pi_company NUMBER,
pi_estab NUMBER
RETURN t_in_list_tab PIPELINED
AS
l_tab t_in_list_tab := t_in_list_tab (NULL, NULL, NULL);
BEGIN
FOR c IN (SELECT v_ref_vehicles.nb_idvehicle, v_ref_vehicles.vc_reference,
v_ref_vehicles.vc_licenceplate
FROM u_ref.v_ref_vehicles
WHERE v_ref_vehicles.nb_idgroup = pi_group
AND v_ref_vehicles.nb_idcompany = pi_company
AND v_ref_vehicles.nb_establ = pi_estab)
LOOP
l_tab.i_group := c.nb_idvehicle;
l_tab.i_company_number := c.vc_reference;
l_tab.estab_number := vc_licenceplate;
END LOOP;
RETURN l_tab;
END;
SELECT *
FROM TABLE (fu_voc_s_vehicles (value1, value2, value3))But looking at your code, your function will return only one record.
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/apex/f?p=107:7
http://htmldb.oracle.com/pls/otn/f?p=31517:1
-------------------------------------------------------------------
Maybe you are looking for
-
APPLE LOOPS AS BASE FOR SONG - CAN I USE IT? - 3RD PARTY?
I have used an iLife Loop as the basis for the pre chorus and chorus of a song I have created. The rest is mine and I have written lyrics for the whole. It seems to me that a third party wrote the jingle and could have a claim on this. Is this correc
-
Finder has gone from slow to nearly unresponsive!!!
I have owned a 2.16 GHz Intel Core 2 Duo MacBook Pro with 2GB of RAM for about a year and upgraded to Leopard the week that it was released, and I had no problems with it off the bat; in fact, my system ran as well as it had in months once I first in
-
Migration problem with password
Having used Migration Assistant to copy from one iMac to another the password for my login is not recognised in the recipient machine.
-
Having trouble with AvailSampPerChan.
I set up DAQmx tasks in an inialization sequence and use the DAQmx Read function in a while loop and it runs great. However, when the operator retrieves a data file, which momentarily interupts the program, the AvailSampPerChan rapidly fills up and
-
IPhone photo sorting sync.
After updating iOS from 4.0.1 to 4.1 I notice photo syncing Changed. When I open an album in iPhone It now opens at the top with oldest pict in the album And I have to scroll to the bottom to look at the most recent pict In the file. Before the updat