Calling Stored Function from TopLink
I have a simple Stored Function that I'm trying to call using TopLink API:
TopLink Version: 10.1.3.3.
Oracle JDBC Driver: ojdbc5.jar (Oracle JDBC Driver version - "11.1.0.6.0-Production+")
Stored Procedure:
Function Get_Email_Address_Id(P_EMAIL_ADDRESS IN varchar2) return number;
TopLink Code:
public String executeStoredFunction() {
TopLinkTemplate tlTemplate = getTopLinkTemplate();
StoredFunctionCall call = new StoredFunctionCall();
call.setProcedureName("EMAIL_ADDRESS_PKG.Get_Email_Address_Id");
call.setResult("FUNCTION_RESULT", String.class);
call.addNamedArgument("P_EMAIL_ADDRESS");
ValueReadQuery query = new ValueReadQuery();
query.setCall(call);
query.addArgument("P_EMAIL_ADDRESS");
Vector parameters = new Vector();
parameters.addElement("1009");
String result = (String)tlTemplate.executeQuery(query, parameters.toArray());
return result;
Error I'm getting:
Exception [TOPLINK-7121] (Oracle TopLink - 10g Release 3 (10.1.3.3.0) (Build 070428)): oracle.toplink.exceptions.ValidationException
Exception Description: DatabasePlatform does not support stored functions
at oracle.toplink.exceptions.ValidationException.platformDoesNotSupportStoredFunctions(ValidationException.java:1299)
at oracle.toplink.queryframework.StoredFunctionCall.prepareInternal(StoredFunctionCall.java:52)
at oracle.toplink.internal.databaseaccess.DatabaseCall.prepare(DatabaseCall.java:494)
at oracle.toplink.internal.queryframework.CallQueryMechanism.prepareCall(CallQueryMechanism.java:102)
at oracle.toplink.internal.queryframework.CallQueryMechanism.prepareExecuteSelect(CallQueryMechanism.java:203)
at oracle.toplink.queryframework.DataReadQuery.prepare(DataReadQuery.java:150)
at oracle.toplink.queryframework.DatabaseQuery.checkPrepare(DatabaseQuery.java:405)
at oracle.toplink.queryframework.DatabaseQuery.checkPrepare(DatabaseQuery.java:375)
at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:598)
at oracle.toplink.queryframework.DataReadQuery.execute(DataReadQuery.java:96)
at oracle.toplink.publicinterface.Session.internalExecuteQuery(Session.java:2089)
at oracle.toplink.publicinterface.Session.executeQuery(Session.java:993)
at oracle.toplink.publicinterface.Session.executeQuery(Session.java:965)
Observations:
Why is TopLink complaining about DatabasePlatform?
I'm using Oracle 10g as my database platform. Did anyone encounter this problem?
I have tried various combinations but it always have same complaint.
Thanks in advance for help.
Hello,
It is complaining because the DatabasePlatform being used doesn't support functions. So the problem is that it is using the DatabasePlatform instead of the Oracle10Platform that you are expecting. How have you defined it? Could you have multiple sessions.xml files, and the one that is being picked not define the Oracle10Platform? Or could you be overriding the login somehow (prelogin event etc) and setting it to use the default DatabasePlatform by accident?
Best Regards,
Chris
Similar Messages
-
Calling Stored Function from Excel
Folks,
Can someone help me with an Excel Macro that will call an Oracle stored function taking in parameter from one of the Excel Cell and return the value from the function into a different cell in the spreadsheet?
ThanksThis is not the right Forum for this query still here is something for you to start with
The oracle function to add 1 to the input parameter
create or replace function AddOne(ID Number) return number is
Numout Number:=0;
begin
numout:=id+1;
return numout;
end;
The Macro in Excel file to run the above function(Please add necessary references for ado connectivity)
Option Explicit
Dim Objconn As ADODB.Connection
Sub Macro1()
Dim StrSql As String
Dim ObjRs As New ADODB.Recordset
Dim I As Long
StrSql = "Provider=OraOLEDB.Oracle.1;Password=swallocation;Persist Security Info=True;User ID=swallocation;Data Source=dumpdb"
Set Objconn = New ADODB.Connection
Objconn.Open StrSql
For I = 2 To Sheet1.Rows.Count
If Not CStr(Sheet1.Cells(I, 1)) = "" Then
ObjRs.Open "select AddOne(" + CStr(Sheet1.Cells(I, 1)) + ") from dual", Objconn
If Not ObjRs.EOF And Not ObjRs.BOF Then
ObjRs.MoveFirst
Sheet1.Cells(I, 2) = ObjRs(0).Value
End If
ObjRs.Close
Else
Exit For
End If
Next
Set ObjRs = Nothing
Objconn.Close
Set Objconn = Nothing
End Sub
Hope you get something to start with
Prakash... -
Calling Stored Function from DOT NET
Hi,
I am trying to call a stored function "PKG_MIS_USER_MASTER.ADD_USER(userid varchar2, password varchar2) return NUMBER" from my DOT NET application.
Everything works fine within TOAD. Can anyone please help me in writing the C# code for calling a stored function along with its return value.
Thanks in Advance.You can (as of 15-JUL-2005) get chapter 5 and chapter 7 of my book from the ODP.NET homepage, which is located here:
http://www.oracle.com/technology/tech/windows/odpnet/index.html
The link is at the bottom of the page.
The direct link is:
http://www.oracle.com/technology/books/pdfs/dotnet_ch5_7.pdf
Chapter 5 covers using PL/SQL from .NET.
- Mark -
How do I call pl/sql function from Toplink
I can easily call a stored procedure from Toplink
====================================================
public Collection executeSelectingStoredProcedure(StoredProcedureCall storedProcedureCall) throws DAOException
Collection returnValue = null;
Session session = null;
session = this.getSession();
returnValue = session.executeSelectingCall(storedProcedureCall);
session.release();
return returnValue;
====================================================
The same does not work for pl/sql functions. Doesnt Toplink treat function calls as a callable statement as in JDBC?
"select <function_name>(<arguments>) from dual" seems to be a work around. If this or using expressions is the only solution can someone please tell me the reasoning behind this shift.
Regards
Aamir DehlaviI have the same problem.
I have a PL/SQL function that returns a number. This function receives 2 parameters. I use StoredProcedureCall plus ValueReadQuery.
Session aSession = SessionManager.getManager().getDefaultSession();
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("CIO_UTILS.COUNT_USER_ROLES_IN_MODULE");
call.addNamedArgument("p_persid");
call.addNamedArgument("p_module");
call.addUnamedOutputArgument("rolesnum", Integer.class);
ValueReadQuery query = new ValueReadQuery();
//query.bindAllParameters();
query.setCall(call);
query.addArgument("p_persid");
query.addArgument("p_module");
Vector parameters = new Vector();
parameters.addElement(persid);
parameters.addElement(theModule);
Integer rolesnum = (Integer) aSession.executeQuery(query,parameters);
aSession.release();
if(rolesnum.intValue()<=0)return false; else return true;
However, I receive the following error:
Exception [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-06550: line 1, column 96:
PLS-00312: a positional parameter association may not follow a named association
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Error Code: 6550
Call:BEGIN CIO_UTILS.COUNT_USER_ROLES_IN_MODULE(p_persid=>'SANCRA2791', p_module=>'PSL_MONITORING', ?); END;
bind => [=> rolesnum]
If comment the line
"call.addUnamedOutputArgument("rolesnum", Integer.class);"
Toplink is trating it as a procedure, and I also receive an error from PL/SQL.
There should have to be a way of make it to receive the resoult somehow, but I do not know what.
Thanks in advance. -
Cannot call ANY stored functions from my Java program
My problem is that I cannot call ANY stored procedure from my Java
program. Here is the code for one of my stored procedures which runs
very well in PL/SQL:
PL/SQL code:
CREATE OR REPLACE PACKAGE types AS
TYPE cursorType IS REF CURSOR;
END;
CREATE OR REPLACE FUNCTION list_recs (id IN NUMBER)
RETURN types.cursorType IS tracks_cursor types.cursorType;
BEGIN
OPEN tracks_cursor FOR
SELECT * FROM accounts1
WHERE id = row_number;
RETURN tracks_cursor;
END;
variable c refcursor
exec :c := list_recs(11)
SQL> print c
COLUMN1 A1 ROW_NUMBER
rec_11 jacob 11
rec_12 jacob 11
rec_13 jacob 11
rec_14 jacob 11
rec_15 jacob 11
Here is my Java code:
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
class list_recs
public static void main(String args[]) throws SQLException,
IOException
String query;
CallableStatement cstmt = null;
ResultSet cursor;
// input parameters for the stored function
String user_name = "jacob";
// user name and password
String user = "jnikom";
String pass = "jnikom";
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
try { Class.forName ("oracle.jdbc.driver.OracleDriver"); }
catch (ClassNotFoundException e)
{ System.out.println("Could not load driver"); }
Connection conn =
DriverManager.getConnection (
"jdbc:oracle:thin:@10.52.0.25:1521:bosdev",user,pass);
try
String sql = "{ ? = call list_recs(?) }";
cstmt = conn.prepareCall(sql);
// Use OracleTypes.CURSOR as the OUT parameter type
cstmt.registerOutParameter(1, OracleTypes.CURSOR);
String id = "11";
cstmt.setInt(2, Integer.parseInt(id));
// Execute the function and get the return object from the call
cstmt.executeQuery();
ResultSet rset = (ResultSet) cstmt.getObject(1);
while (rset.next())
System.out.print(rset.getString(1) + " ");
System.out.print(rset.getString(2) + " ");
System.out.println(rset.getString(3) + " ");
catch (SQLException e)
System.out.println("Could not call stored function");
e.printStackTrace();
return;
finally
cstmt.close();
conn.close();
System.out.println("Stored function was called");
Here is how I run it, using Win2K and Oracle9 on Solaris:
C:\Jacob\Work\Java\Test\Vaultus\Oracle9i\FunctionReturnsResultset>java
list_recs
Could not call stored function
java.sql.SQLException: ORA-00600: internal error code, arguments:
[ttcgcshnd-1], [0], [], [], [], [], [], []
at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:889)
at
oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:490)
at
oracle.jdbc.driver.OracleStatement.getCursorValue(OracleStatement.java:2661)
at
oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4189)
at
oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4123)
at
oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:541)
at list_recs.main(list_recs.java:42)
C:\Jacob\Work\Java\Test\Vaultus\Oracle9i\FunctionReturnsResultset>
Any help is greatly appreciated,
Jacob NikomThank you for your suggestion.
I tried it, but got the same result. I think the difference in the syntax is due to the Oracle versus SQL92 standard
conformance. Your statament is the Oracle version and mine is the SQL92. I think both statements are acceptable
by the Oracle.
Regards,
Jacob Nikom -
Calling database stored function from Entity Object
Hi,
I want to call a database stored function from create() method of Entity Object.
Database function returns some value.
Can anybody suggest me some way to do it.You can try the following:
make a String whit your function call, I dont know if this is the correct SQL syntax for a function, it should be for a stored procedure.
String call = "begin; callyourfunction; end;"
PreparedStatement ps = getDBTransaction().createPreparedStatement(call,0);
ps.execute();
ResultSet rs = ps.getResultSet();
You can now read the data from the function from the rowset.
Be sure to cleanup the PreparedStatement when your done whit it to avoid open database connections.
ps.close();ps=null; -
Calling Stored procedure from Forms 6i
Dear all,
I have a stored procedure having INand INOUT parameters. I need to call it from Forms 6i triggers. Will you please tell me the syntax for calling stored procedure and stored function from Forms 6i and report 6i.
Saibaldas
[email protected]Just the same as for a local procedure, the only restrictions concern package public variables which are not visible from client side PL/SQL, and you probly want to keep the interfaces simple as client side PL/SQL (e.g. the Forms and Reports engines) don't support the same range of datatypes that the database does.
-
Problem in calling stored Procedure through Toplink
Hi ,
I'm doing POC of calling stored thru toplink but facing some issues. Any pointers to it would be helpful.
This is my javaCode used to call stored proc through toplink:-
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("testdeleteLeafBox");
call.addNamedInOutputArgumentValue(
"box_id", // procedure parameter name
new Integer("1455"), // in argument value
"box_id", // out argument field name
Integer.class // Java type corresponding to type returned by procedure
ValueReadQuery query = new ValueReadQuery();
query.setCall(call);
Integer metricLength = (Integer) session.executeQuery(query);
My Stored Procedure is :-
create or replace procedure testdeleteLeafBox(
v_box_id IN NUMBER ,
result OUT number
is
v_result number;
BEGIN
SELECT client_id INTO v_result FROM tb_gvhr_box WHERE box_id=v_box_id;
result:=v_result;
end testdeleteLeafBox;
Thrown exception is :-
[TopLink Warning]: 2006.02.24 06:35:47.077--DatabaseSessionImpl(650)--Exception [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TESTDELETELEAFBOX'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Error Code: 6550
Call:BEGIN testdeleteLeafBox(box_id=>?); END;
bind => [1455 => box_id]
Query:ValueReadQuery()
Exception breakpoint occurred at line 1927 of Session.java.
oracle.toplink.exceptions.DatabaseException: java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TESTDELETELEAFBOX'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignoredThe stored procedure defined in the db has one IN and one OUT parameter, therefore in StoredProcedureCall you'll need to have one IN one OUT parameter as well (instead of a single INOUT):
call.addNamedArgumentValue(
"v_box_id", //procedure IN parameter name
new Integer("1455"));
call.addNamedOutputArgument(
"result", //procedure OUT parameter name
"box_id", // out argument field name
Integer.class // OUT parameter Java type); -
How to call oracle function from ejb3
i'm trying to call an oracle query-function from ejb3.
The oracle function:
create or replace FUNCTION getSecThreadCount(secId in NUMBER,avai in NUMBER)
RETURN SYS_REFCURSOR is cur SYS_REFCURSOR;
m_sql VARCHAR2(250);
BEGIN
m_sql:='select count(thrId) from thread where secId='|| secid||'
and thrAvai='|| avai;
open cur for m_sql;
return cur;
END;
I'v tried several ways to call it,but all failed:
1. the calling code:
public Object getSectionThreadCount(int secId,int avai){
Query query=manager.createNativeQuery("{call getSecThreadCount(?,?) }");
query.setParameter(1, secId);
query.setParameter(2, avai);
return query.getSingleResult();
but i got the exception:
Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query; nested exception is: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLException: ORA-06550: row 1, col 7:
PLS-00221: 'GETSECTHREADCOUNT' not procedure or not defined
ORA-06550: row 1, col 7:
PL/SQL: Statement ignored
2. the calling code:
@SqlResultSetMapping(name = "getSecThreadCount_Mapping")
@NamedNativeQuery(name = "getSecThreadCount",
query = "{?=call getSecThreadCount(:secId,:avai)}",
resultSetMapping = "getSecThreadCount_Mapping",
hints = {@QueryHint(name = "org.hibernate.callable", value = "true"),
@QueryHint(name = "org.hibernate.readOnly", value = "true")})
public Object getSectionThreadCount(int secId,int avai){
Query query=manager.createNamedQuery("getSecThreadCount");
query.setParameter("secId", secId);
query.setParameter("avai", avai);
return query.getSingleResult();
but i run into the exception:
Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query; nested exception is: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLException: lost in index IN or OUT parameter:: 3
By the way, i have successfully called the function from hibernate. And i use oracle 11g, JBoss5 RC1.
Could anyone tell me how to call the function from EJB3?
Thanks.Here's a working model:
package.procedure: (created in example schema scott)
CREATE OR REPLACE package body data_pkg as
type c_refcursor is ref cursor;
-- function that return all emps of a certain dept
function getEmployees ( p_deptId in number
return c_refcursor
is
l_refcursor c_refcursor;
begin
open l_refcursor
for
select e.empno as emp_id
, e.ename as emp_name
, e.job as emp_job
, e.hiredate as emp_hiredate
from emp e
where e.DEPTNO = p_deptId;
return l_refcursor;
end getEmployees;
end data_pkg;
/entity class:
package net.app.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedNativeQuery;
import javax.persistence.QueryHint;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@SuppressWarnings("serial")
@Entity
@Table (name="emp")
@SequenceGenerator(name = "EmployeeSequence", sequenceName = "emp_seq")
@NamedNativeQuery( name = "getEmpsByDeptId"
, query = "{ ? = call data_pkg.getEmployees(?)}"
, resultClass = Employee.class
, hints = { @QueryHint(name = "org.hibernate.callable", value = "true")
, @QueryHint(name = "org.hibernate.readOnly", value = "true")
public class Employee implements Serializable
@Id
@Column(name="emp_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EmployeeSequence")
private int id;
@Column(name="emp_name")
private String name;
@Column(name="emp_job")
private String job;
@Column(name="emp_hiredate")
private Date hiredate;
// constructor
public Employee (){}
// getters and setters
public int getId()
return id;
etc...session bean:
package net.app.entity;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import net.app.entity.Employee;
import net.app.iface.ScottAdmin;
@Stateless
public class ScottAdminImpl implements ScottAdmin
@PersistenceContext
private EntityManager entityManager;
@SuppressWarnings("unchecked")
public List<Employee> getEmployeesByDeptId(int deptId)
ArrayList<Employee> empList;
try
Query query = entityManager.createNamedQuery("getEmpsByDeptId");
query.setParameter(1, deptId);
empList = (ArrayList<Employee>) query.getResultList();
return empList;
catch (Exception e)
e.printStackTrace(System.out);
return null;
}client:
package net.app.client;
import java.util.List;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import net.app.entity.Employee;
import net.app.iface.ScottAdmin;
public class ScottClient
public static void main(String[] args)
try
// create local interface
InitialContext ctx = new InitialContext();
ScottAdmin adminInterface = (ScottAdmin) ctx.lookup("ScottAdminImpl/remote");
// select employees by deptno
int deptno = 20;
List<Employee> empList = adminInterface.getEmployeesByDeptId(deptno);
// output
System.out.println("Listing employees:");
for (Employee emp : empList)
System.out.println(emp.getId() + ": " + emp.getName() + ", " + emp.getJob() + ", " + emp.getHiredate());
catch (NamingException e)
e.printStackTrace(System.out);
}Basically you just ignore the refcursor outbound parameter.
This is a stored function, have yet to try outbound refcursor parameters in stored procedures...
Edited by: _Locutus on Apr 2, 2009 2:37 PM -
How to call stored procedure from Pro*C
How to call stored procedure from Pro*C ?
my system spec is SuSE Linux 9.1, gcc version : 3.3.3, oracle : 10g
my Pro*C code is the following..
EXEC SQL EXECUTE
begin
test_procedure();
end;
END-EXEC;
the test_procedure() has a simple update statement. and it works well in SQL Plus consol. but in Pro*C, there is a precompile error.
will anybody help me what is the problem ??I'm in the process of moving C files (with embedded SQL, .PC files) from Unix to Linux. One program I was trying to compile had this piece of code that called an Oracle function (a standalone), which compiled on Unix, but gives errors on Linux:
EXEC SQL EXECUTE
BEGIN
:r_stat := TESTSPEC.WEATHER_CHECK();
END;
END-EXEC;
A call similar to this is in another .PC file which compiled on Linux with no problem. Here is what the ".lis" file had:
Pro*C/C++: Release 10.2.0.1.0 - Production on Mon Jun 12 09:26:08 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Error at line 193, column 5 in file weather_check.pc
193 BEGIN
193 ....1
193 PCC-S-02346, PL/SQL found semantic errors
Error at line 194, column 8 in file weather_check.pc
194 :r_stat := TESTSPEC.WEATHER_CHECK();
194 .......1
194 PLS-S-00000, Statement ignored
Error at line 194, column 18 in file weather_check.pc
194 :r_stat := TESTSPEC.WEATHER_CHECK();
194 .................1
194 PLS-S-00201, identifier 'TESTSPEC.WEATHER_CHECK' must be declared
Pro*C/C++: Release 10.2.0.1.0 - Production on Mon Jun 12 09:26:08 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
System default option values taken from: /oracle_client/product/v10r2/precomp/ad
min/pcscfg.cfg
Error at line 194, column 18 in file weather_check.pc
:r_stat := TESTSPEC.WEATHER_CHECK();
.................1
PLS-S-00201, identifier 'TESTSPEC.WEATHER_CHECK' must be declared
Error at line 194, column 8 in file weather_check.pc
:r_stat := TESTSPEC.WEATHER_CHECK();
.......1
PLS-S-00000, Statement ignored
Semantic error at line 193, column 5, file weather_check.pc:
BEGIN
....1
PCC-S-02346, PL/SQL found semantic errors -
Hi all,
Trying to call a stored function from vfp5 using odbc, not ado. I'm having issues with the correct syntax of the statement. Can I not use the standard vfp sqlexec() command? ( i.e. sqlexec( connhandle, "{call package.function()}, "returncursor" ) Any help would be great since my customer has no clue on this, and frankly, neither do I.This is supported in the next code drop of the XSQL Servlet. Due out on OTN in the next couple of weeks.
-
How to call a function from asp
Hi!, I'd like to know how to call a function from an asp page. I've written:
set rs = server.createobject("Adodb.recordset")
rs.open "call dbo.sf_Obt_Des_Producto ('0000161')",Conn
if err.description <> "" then
response.write ("No se pudo! :(")
else
response.write ("rs: " & rs(0))
end if
rs.close
set rs = nothing
but there is an error:
ORA-06576: not a valid function or procedure name
Please is very urgent!!!
Thanks.
Angie.You need to use the syntax "{call <procedure_name>}".
The {call } syntax tells the OLE DB provider that it needs to translate the call into whatever the database's procedure calling syntax is. This means that even though different databases have different syntax for calling stored procedures, your OLE DB code can be run against any of them without changing.
Justin -
Trying to call a function from C#
Hi all,
I am having problems calling a function that returns a sys refcursor and takes a varchar2 as an input. From the SQL Developer IDE I see that the function is run like
DECLARE
X_AR_MHTR VARCHAR2(200);
v_Return sys_refcursor;
BEGIN
X_AR_MHTR := 697678;
v_Return := CMS_SMS.FOR_WEB.WEB_STATION_1(
X_AR_MHTR => X_AR_MHTR
/* Legacy output:
DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
:v_Return := v_Return; --<-- Cursor
END;
here is my C# code
public static void getTilemetriseis(bool isLemessos, string AMSet, out OracleDataReader dr)
DataSet ds = new DataSet();
OracleDataAdapter ad = new OracleDataAdapter();
OracleCommand cmd = new OracleCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "CMS_SMS.FOR_WEB.WEB_Station_1";
if (isLemessos)
cmd.Parameters.Add("X_AR_MHTR", OracleDbType.Varchar2, ConfigurationManager.AppSettings["LemessosArMhtr"].ToString(), ParameterDirection.Input);
cmd.Parameters.Add(new OracleParameter("anexoflCur", OracleDbType.RefCursor, ParameterDirection.ReturnValue));
// ad.SelectCommand.CommandText = string.Format(@"select m_code,ar_mhtr,city,address,stcode
// from cms_sms.FOR_WEB.flowmetersall where ar_mhtr = {0}
// order by length(ar_mhtr),ar_mhtr", ConfigurationManager.AppSettings["LemessosArMhtr"].ToString());
else
cmd.Parameters.Add("X_AR_MHTR", OracleDbType.Varchar2, "697678", ParameterDirection.Input);
cmd.Parameters.Add(new OracleParameter("v_Return", OracleDbType.RefCursor, ParameterDirection.ReturnValue));
// ad.SelectCommand.CommandText = string.Format(@"select m_code,ar_mhtr,city,address,stcode
// from cms_sms.FOR_WEB.flowmetersall where ar_mhtr= -1
// order by length(ar_mhtr),ar_mhtr", AMSet);
cmd.Connection = OracleDBManager.getOracleCMSConnection();
cmd.ExecuteNonQuery();
dr = (OracleDataReader)cmd.Parameters["v_Return"].Value;
cmd.Connection.Close();
The error rises on cmd.ExecuteNonQuery() and is described as
ORA-06550:
PLS-00306: wrong number or type of argument
Any ideas?Off the top of my head, your parameter type on the second parameter is wrong. The function doesn't have a return value, one of the parameters contains it. So the second parameter's type can't be ReturnValue (should be output).
Either that or change the function to only have one parameter and add RETURN sys_refcursor into the definition, at which point you can use ReturnValue.
Here's an example: http://stackoverflow.com/questions/1773534/what-is-the-right-way-to-call-an-oracle-stored-function-from-ado-net-and-get-the
Edited by: Tridus on Mar 20, 2013 10:24 AM -
Calling stored procedures from entity object and application module
Hello
I've put in place an EntiyImpl base class containg helper methods to call stored procedures.
I now need to call stored procedures from the application module.
Apart from creating an application module base class and duplicating the helper method code is there a way
to share the helper methods for calling stored procedures between the entity impl and application module impl ?
Regards
PaulDoes the helper code depend on features of a particular entity object instance, beyond its database transaction?
If so, I'm not sure I see how it could be used from an application module class.
If not, here's what you do:
Step 1:
Parametrize the database transaction--you might even want to. So instead of
protected myHelperMethod(Object someParam) {
DBTransaction trans = getDBTransaction();
change this to
protected myHelperMethod(DBTransaction trans, Object someParam) {
Step 2: make the method public and static--once you parameterize the DBTransaction, you should be able to do this.
public static myHelperMethod(DBTransaction trans, Object someParam) {
Step 3: Remove the method from your EntityImpl base class into a utility class:
public abstract class PlSqlUtils {
private PlSqlUtils() {}
public static myHelperMethod(DBTransaction trans, Object someParam) {
When you want to call the method from an application module, entity object, or even view object class, call
PlSqlUtils.myHelperMethod(getDBTransaction(), paramValue);
Unlike Transaction.executeCommand(), this lets you provide functionality like setting procedure parameter values, retrieving OUT parameter values, etc.
Hope this helps,
Avrom -
Calling Stored Procedures from Discoverer
Does anyone know if I can call stored procedures from Discoverer? I know it supports Registered PL/SQL functions. If yes, can I find any documentation. Any information will be very helpful.
Thanks in advance!
NingOne way I can think of to do that would be to use function with pragma restrict references. You can then use the function as a column in a SQL query to make a folder in Discoverer.
Maybe you are looking for
-
Ipod touch not showing in My Computer
Ipod touch isn't showing in the My Computer folder, I need to access the media on the ipod but not through itunes..?
-
OIF 11g How do I pass a static value in an attribute inside a SAML response
This is what Oracle documentation says you should do: http://docs.oracle.com/cd/E21764_01/oim.1111/e13400/configoif.htm#SFSAG1696 For testing purposes I implemented the example given in the documentation. It doesn't seem to work. Using WLST I queried
-
@Prompt causing funny issues
Guys, I am migrating an universe which is pointing to a SQL 2005 DB from 6.5 to xi 3.1 FP 1.5 and i am facing the below issue. In the universe i have a condition using the prompt function and it is as below: ((tablenamel.name in @Prompt('Select Name
-
Why are the Apple mods deleting and locking threads?
I would like an answer as to why the mods are deleting and locking threads that have to do with the error that pervasive in the iPod 1.1 upgrade. It seems that Apple will not acknowledge it but some of us are trying to find an answer and Apple locks
-
What does one do if your email account is hacked and an email is sent in your name asking for money
What does one do if your email account is hacked? Someone apparently has my email address and my contact list. They sent an urgent email to the address list saying I was stranded in Italy and to send money. Do I send am email to everyone in my add