Passing DATE parameters to Oracle Stored Procedures using ADO
Does anyone know how can I pass a date parameter to an Oracle
Stored Procedure? The IN parameter of the procedure is of type
DATE and the ADO parameter is of type DBDate (I've tried Date
and DBTimeStamp,too). The execution freezes at "Cmd.Execute".
Can anyone suggest a solution?
Thanx for any tips
As far as I know the documentation on CR & stored procedures says that the REF CURSOR has to be a strongly bound one.
Could you go into a little more detail? Do you mean I should put a multi-valued parameter into a REF CURSOR? Can you post some code snippets here?
Similar Messages
-
PLS-00306:NET to call Oracle stored procedure,Use Array parameters
Development Environment:Windows 2003 SP2+Oracle 10g
. NET to call Oracle stored procedure, use an array of types of parameters
Step1:(In the Oracle database define an array of types)
CREATE OR REPLACE TYPE STRING_VARRAY AS VARRAY (1000) OF NVARCHAR2(255)
OR
CREATE OR REPLACE type string_array is table of nvarchar2(255)
Step2:
CREATE OR REPLACE PROCEDURE Test
(i_test in string_varray,o_result out int)
IS
BEGIN
o_result:=i_test.count;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
o_result:=0;
END arraytest;
Step3:
ODP.NET(Oracle 10g)
OracleConnection conn = new OracleConnection("User Id=test;Password=test;Data Source=test");
OracleCommand cmd = new OracleCommand("Test", conn);
cmd.CommandType = CommandType.StoredProcedure;
string[] str = new string[2] { "11", "222" };
cmd.ArrayBindCount=2;
OracleParameter p1 = new OracleParameter("i_test", OracleDbType.NVarChar);
p1.Direction = ParameterDirection.Input;
p1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
p1.Value = str;
p1.ArrayBindSize=new int[2]{2,3};
p1.ArrayBindStatus = new OracleParameterStatus[2]{
OracleParameterStatus.Success,
OracleParameterStatus.Success
cmd.Parameters.Add(p1);
OracleParameter p2 = new OracleParameter("o_result", OracleDbType.Int32);
p2.Direction = ParameterDirection.Output;
P2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
p2.Value=0;
cmd.Parameters.Add(p2);
int i = 0;
try
conn.Open();
cmd.ExecuteNonQuery();
i =(int) p2.Value;
catch (Exception ex)
finally
conn.Close();
Error:
Execution Failed:ORA-06550:Line 1,Column 7:
PLS-00306:Test parameters when calling the number or types of errors
ORA-06550:Line 1,Column 7:
PL/SQL:Statement ignoredHi,
See the answer in [this thread|http://forums.oracle.com/forums/thread.jspa?threadID=909564&tstart=0]
Hope it helps,
Greg -
. NET to call Oracle stored procedure, use an array of types of parameters
. NET to call Oracle stored procedure, use an array of types of parameters
Step1:(In the Oracle database define an array of types)
CREATE OR REPLACE TYPE STRING_VARRAY AS VARRAY (1000) OF NVARCHAR2(255)
Step2:
CREATE OR REPLACE PROCEDURE Test
(i_test in string_varray,o_result out int)
IS
BEGIN
o_result:=i_test.count;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
o_result:=0;
END arraytest;
Step3:
Use System.Data.OracleClient
C# Code:
OracleConnection conn = new OracleConnection("User Id=test;Password=test;Data Source=test");
OracleCommand cmd = new OracleCommand("Test", conn);
cmd.CommandType = CommandType.StoredProcedure;
string[] str = new string[] { "11", "22" };
OracleParameter p1 = new OracleParameter("i_test", OracleType.NVarChar);
p1.Direction = ParameterDirection.Input;
p1.Value = str;
cmd.Parameters.Add(p1);
OracleParameter p2 = new OracleParameter("o_result", OracleType.Int32);
p2.Direction = ParameterDirection.Output;
cmd.Parameters.Add(p2);
int i = 0;
try
conn.Open();
cmd.ExecuteNonQuery();
i =(int) p2.Value;
catch (Exception ex)
finally
conn.Close();
Error:
Execution Failed:ORA-06550:Line 1,Column 7:
PLS-00306:Test parameters when calling the number or types of errors
ORA-06550:Line 1,Column 7:
PL/SQL:Statement ignored
Edited by: user10133982 on Jun 4, 2009 7:13 AM. NET to call Oracle stored procedure, use an array of types of parameters
The use of ODP.net(Oracle 10g), the error is still the same
Step1:(In the Oracle database define an array of types)
CREATE OR REPLACE TYPE STRING_VARRAY AS VARRAY (1000) OF NVARCHAR2(255)
Step2:
CREATE OR REPLACE PROCEDURE Test
(i_test in string_varray,o_result out int)
IS
BEGIN
o_result:=i_test.count;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
o_result:=0;
END arraytest;
Step3:
ODP.NET(Oracle 10g)
OracleConnection conn = new OracleConnection("User Id=test;Password=test;Data Source=test");
OracleCommand cmd = new OracleCommand("Test", conn);
cmd.CommandType = CommandType.StoredProcedure;
string[] str = new string[2] { "11", "222" };
cmd.ArrayBindCount=2;
OracleParameter p1 = new OracleParameter("i_test", OracleDbType.NVarChar);
p1.Direction = ParameterDirection.Input;
p1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
p1.Value = str;
p1.ArrayBindSize=new int[2]{2,3};
p1.ArrayBindStatus = new OracleParameterStatus[2]{
OracleParameterStatus.Success,
OracleParameterStatus.Success
cmd.Parameters.Add(p1);
OracleParameter p2 = new OracleParameter("o_result", OracleDbType.Int32);
p2.Direction = ParameterDirection.Output;
P2.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
p2.Value=0;
cmd.Parameters.Add(p2);
int i = 0;
try
conn.Open();
cmd.ExecuteNonQuery();
i =(int) p2.Value;
catch (Exception ex)
finally
conn.Close();
Error:
Execution Failed:ORA-06550:Line 1,Column 7:
PLS-00306:Test parameters when calling the number or types of errors
ORA-06550:Line 1,Column 7:
PL/SQL:Statement ignored
Edited by: user10133982 on Jun 5, 2009 7:48 AM -
Passing XMLType Data into oracle stored procedure using JDBC
Hi Friends,
I have requirement where my oracle stored procedure accepts XML file as an input. This XML File is generated in runtime using java, I need to pass that xml file using JDBC to oracle stored procedure. Please let me know the fesibile solution for this problem.
Following are the environment details
JDK Version: 1.6
Oracle: 10g
Server: Tomcat 6.x
Thanks in Advanceuser4898687 wrote:
I have requirement where my oracle stored procedure accepts XML file as an input. This XML File is generated in runtime using java, I need to pass that xml file using JDBC to oracle stored procedure. Please let me know the fesibile solution for this problem.As stated - no.
A 'file' is a file system entity. There is no way to pass a 'file' anywhere. Not PL/SQL. Not java.
Now you can pass a file path (a string) in java and to PL/SQL.
Or you can pass xml data (a string) in java and to PL/SQL. For PL/SQL you could use eithe a varchar2, if the xml is rather small, or a blob/clob. -
Passing parameters to oracle stored procedure in business objects universe
Hello,
Wanted to create a web intelligence usind oracle stored procedure.
Create the following SP
create or replace procedure proc_name1
proc_freq in number,
proc_cur1 in out sys_refcursor
as
begin
INSERT INTO
cc VALUES
( 'Frequency Value = ' || proc_freq, SYSDATE) ;
COMMIT ;
--daily
if(proc_freq = 2) then
open proc_cur1 for SELECT
EVENT_DATE
FROM rqm_mapsigng_dly_stats;
end if;
end;
tried using the above SP in universe, it is needed to pass the parameter for proc_freq, when i pass value 2 , in oracle it is passed as 0(is being traced in rqm_checkpoint table)
Hence the table cannot be inserted in the universe.
Can anyone tell why the value is not being passed correctlyI believe when you're doing it with an insert, you're saying "execute this insert statement a bunch of times, here's all the values in advance", which is different than passing an array to a stored procedure where you want it to execute once.
Oracle's ODBC driver doesnt support Associative Arrays (aka index-by tables).
Hope it helps,
Greg -
Calling an Oracle stored procedure using Toplink API - Please help
Hi,
We are evaluating Toplink as a possible data access layer in large service-oriented application. The ability to call db stored procedures from within business object layer is crucial for our architechture.
I am trying to follow toplink application developer's guide examples on how to call stored procedures using toplink.
I have the folling java code:
call.setProcedureName("PR_ROMAN_TEST");
call.addNamedArgument("IN_PARAM");
call.addNamedOutputArgument("OUT_PARAM");
ValueReadQuery query = new ValueReadQuery();
query.setCall(call);
query.addArgument("IN_PARAM");
Vector params = new Vector();
params.addElement(new Integer(5));
Number result = (Number) session.executeQuery(query, params);
This generates the following SQL statement:
BEGIN PR_ROMAN_TEST(IN_PARAM=>5, OUT_PARAM=>?); END;
An attempt to execute it causes a
java.sql.SQLException: Invalid column index.
As I understand it, this exception is thrown because of the "?" in place of the out-parameter value holder.
The SQL statement that I would want toplink to generate and execute should look like:
DECLARE result number; BEGIN PR_ROMAN_TEST(IN_PARAM=>5, OUT_PARAM=>result); END;
, but how do I achieve it and how do I capture the return value, all using toplink api?
Please help
Thank you in advance,
RomanI read the conversation above. I am running into a similar kind of problem. I get the following error.
<an exponent (**)> <> or != or ~= >= <= <> and or like between || The symbol "." was subs Error Code: 6550Local Exception Stack: Exception [TOPLINK-4002] (OracleAS TopLink - 10g (9.0.4.5) (Build 040930)): oracle.toplink.exceptions.DatabaseException Exception Description: java.sql.SQLException: ORA-06550: line 1, column 38: PLS-00103: Encountered the symbol "NAME" when expecting one of the following:. ( ) , * @ % &' | = - + < / > at in is mod not range rem =>.. <an exponent (**)> <> or != or ~= >= <= <> and or like as between from using || The symbol "." was substituted for "NAME" to continue.ORA-06550: line 1, column 55: PLS-00103: Encountered the symbol "ID" when expecting one of the following:. ( ) , * @ % &' | = - + < / > at in is mod not range rem =>.. <an exponent (**)> <> or != or ~= >= <= <> and or like between || The symbol "." was subs Internal Exception: java.sql.SQLException: ORA-06550: line 1, column 38:PLS-00103: Encountered the symbol "NAME" when expecting one of the following . ( ) , * @ % &' | = - + < / > at in is mod not range rem =>.. <an exponent (**)> <> or != or ~= >= <= <> and or like as between from using || The symbol "." was substituted for "NAME" to continue.ORA-06550: line 1, column 55:PLS-00103: Encountered the symbol "ID" when expecting one of the following: . ( ) , * @ % &' | = - + < / > at in is mod not range rem =>.. <an exponent (**)> <> or != or ~= >= <= <> and or like between || The symbol "." was subs Error Code: 6550 at oracle.toplink.exceptions.DatabaseException.sqlException(DatabaseException.java:227)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:733)
at oracle.toplink.internal.databaseaccess.DatabasePlatform.executeStoredProcedureCall(DatabasePlatform.java:1605)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:649)
at oracle.toplink.threetier.ServerSession.executeCall(ServerSession.java:506)at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(CallQueryMechanism.java:131)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(CallQueryMechanism.java:115)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeSelectCall(CallQueryMechanism.java:194)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeSelect(CallQueryMechanism.java:175)
at oracle.toplink.queryframework.DirectReadQuery.executeNonCursor(DirectReadQuery.java:65)
at oracle.toplink.queryframework.DataReadQuery.execute(DataReadQuery.java:73)
at oracle.toplink.queryframework.ValueReadQuery.execute(ValueReadQuery.java:59)
at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:493)
at oracle.toplink.queryframework.ReadQuery.execute(ReadQuery.java:125)
at oracle.toplink.publicinterface.Session.internalExecuteQuery(Session.java:1958)
at oracle.toplink.threetier.ServerSession.internalExecuteQuery(ServerSession.java:629)
at oracle.toplink.threetier.ClientSession.internalExecuteQuery(ClientSession.java:392)
at oracle.toplink.publicinterface.Session.executeQuery(Session.java:1086)
at oracle.toplink.publicinterface.UnitOfWork.internalExecuteQuery(UnitOfWork.java:2246)
at oracle.toplink.publicinterface.Session.executeQuery(Session.java:1086)
at oracle.toplink.publicinterface.Session.executeQuery(Session.java:1055)
at com.eplinc.common.persistence.toplink.TopLinkTemplate$2.readFromSession(TopLinkTemplate.java:181)
at com.eplinc.common.persistence.toplink.SessionReadCallback.doInTopLink(SessionReadCallback.java:59)
at com.eplinc.common.persistence.toplink.TopLinkTemplate.execute(TopLinkTemplate.java:110)
at com.eplinc.common.persistence.toplink.TopLinkTemplate.executeQuery(TopLinkTemplate.java:178)
at com.eplinc.common.persistence.toplink.TopLinkTemplate.executeQuery(TopLinkTemplate.java:172)
at com.epl.outletteller.dao.toplink.TopLinkOIDGeneratorDAO.generateId(TopLinkOIDGeneratorDAO.java:45)
The call I am making is as follows :
public long generateId(String name, long outletId) throws DataAccessException {
TopLinkTemplate tlTemplate = new TopLinkTemplate();
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("AUTONUM.GET_NEXT_VALUE");
call.addNamedArgument("autonum name");
call.addNamedArgument("outlet id");
call.addNamedOutputArgument("OUTPUT_1");
ValueReadQuery query = new ValueReadQuery();
query.setCall(call);
query.addArgument("autonum name");
query.addArgument("outlet id");
Object[] parameters = new Object[2];
parameters[0] = name;
parameters[1] = Long.toString(outletId);
Number uniqueNumber = (Number)tlTemplate.executeQuery(query,parameters);
return uniqueNumber.longValue();
This is my Table AUTONUM_SETTING
AUTONUM_NAME AUTONUM_TYPE START_VAL END_VAL INCREMENT_VALUE
TRAN_NUM GLOBAL 1 999999 1
TRACE_NUM OUTLET 1 999999 1
Any help would be appreciated. Thanks -
Errors in calling Oracle stored procedure using java CallableStatement
Hello,
I have an oracle stored procedure below, it has been tested in PL/SQL without errors. During testing, in_c_file_type="F"; out_n_seqno_freeformat=120139596 and out_n_seqno_commaseprated is null (empty in value column).
When I run the program in Eclipse (windows xp), error messages is below: (It stopped at line 'cstme.execute();' )
Message:ORA-06550: line 1, column 26: PLS-00103: Encountered the symbol "" when expecting one of the following: . ( ) , * @ % & | = - + < / > at in is mod remainder not range rem => .. <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ as between from using || indicator multiset member SUBMULTISET_ The symbol ", was inserted before "" to continue. Error code:6550 SQL statement:65000 {code} Does anyone know what cause the error? It seems like something is missing in the stored procedure. But the stored procedure passes the test in the PL/SQL. The oracla driver I used is Oracle thin driver. Oracle version is 10.2.g Thanks in advance. northcloud {code} create or replace procedure SP_GET_SEQNO_2( in_c_file_type in char, out_n_seqno_freeformat out integer, out_n_seqno_commaseprated out integer) is n_seqno_commaseprated integer; n_seqno_freeformat integer; begin if in_c_file_type ='F' THEN SELECT message_counter.nextval INTO n_seqno_freeformat FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_freeformat,empty_clob(),empty_clob()); elsif in_c_file_type ='C' THEN SELECT message_counter.nextval INTO n_seqno_commaseprated FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_commaseprated,empty_clob(),empty_clob()); else SELECT message_counter.nextval INTO n_seqno_freeformat FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_freeformat,empty_clob(),empty_clob()); SELECT message_counter.nextval INTO n_seqno_commaseprated FROM dual; insert into temp_stroperations (record_id,OUTPUT_STR,INPROCESS_STR) values (n_seqno_commaseprated,empty_clob(),empty_clob()); end if; out_n_seqno_freeformat := n_seqno_freeformat; out_n_seqno_commaseprated := n_seqno_commaseprated; end SP_GET_SEQNO_2; {code} ----- A part of java code I used to call the stored procedure is here. {code} String escapeString = "{call SP_GET_SEQNO_2 (? ? ?)}"; CallableStatement cstme = null; try { cstme = con.prepareCall(escapeString); cstme.setString(1, "F"); cstme.registerOutParameter(2, java.sql.Types.INTEGER); cstme.registerOutParameter(3, java.sql.Types.INTEGER); cstme.execute(); int seqNoFreeformat=0, seqNocommasepreted=0; seqNoFreeformat = cstme.getInt(2); seqNocommasepreted = cstme.getInt(3); System.out.println ("In ConvertXML.processStoredProcedure(), seqNoFreeformat= "+seqNoFreeformat+";seqNocommasepreted="+seqNocommasepreted); } catch (SQLException e) { //System.out.println ("In ConvertXML.processStoredProcedure(), SQLException: "+e); System.err.println("Message:"+e.getMessage()); System.err.println("Error code:"+e.getErrorCode()); System.err.println("SQL statement:"+e.getSQLState()); log.log(Level.INFO, log.getName() + " - SQLException : "+e); } {code}es5f2000 wrote:
jschell wrote:
That works?I dunno. The below definitely works, but like I said, I've only
ever done it with one output parameter (and that has always
been a ResultSet).
String callableQuery = "{?= call my_package.my_call(?, ?)}"
Yes I have done that and at least in terms of my code it wasn't just a result set.
But not with two. -
Oracle Stored Procedure using CR2011
We have CR11.5 reports that works using Oracle Stored Procedure. We are planning to upgrade to CR2011 but the report fails with the error message Failed to retrieve data from database. Details HY000 may not perform insert/delete/update operation inside a READ ONLY transaction
Hello Don,
I am trying to use OLE DB to access the stored procedure in the oracle. I can see the stored procedure in the crystal report with the fields but whenever i refresh i face a message box
the text of the message box is as follows
Crystal Reports
Failed to open a rowset.
Details: ADO Error Code: 0x80040e14
Source: Microsoft OLE DB Provider for Oracle
Description: ORA-06550: line 1, column 42:
PLS-00363: expression ' NULL' cannot be used as an assignment target
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Native Error: 6550
OK
My stored procedure code is as follows
Create or Replace Package pckReports
AS
type agent_list is ref cursor return BAT_AGENTLIST%rowtype;
END;
CREATE or REPLACE PROCEDURE BatAgentlistReport (p_Recordset IN OUT pckReports.agent_list) AS
BEGIN
Open p_Recordset FOR
select * from bat_agentlist;
END;
The Ole db version is :- 10.1.0.4.0
The stored procedure is developed in Oraclient10g.
I am developing the stored procedure from the microsoft visual studio using a connection with the provider :- OraOLEDB.Oracle.1 -
How to call Oracle Stored Procedure using EDQ
Can someone tell me how to use Oracle Stored Procedure call in EDQ, sample scripts/steps will be really helpful. Thanks!
It is also possible to do this using a custom processor in EDQ. The processor needs to do something very similar to the external task above (opens a DB connection, authenticates, runs a stored procedure).
If you need this, please talk us through the use case so we can determine if it is the best fit. In some ways, an external task is better as logically a stored procedure call is normally divorced from any process logic in EDQ.
Regards,
Mike -
Can't execute Oracle Stored Procedure using JDBC
Hi all,
I'm fairly new to JDBC and Oracle, so pardon my ignorance/lack of knowledge in this subject matter. I am trying to call a stored procedure named get_countries that has no parameters using JDBC. I do this by executing the following lines of code:
CallableStatement cs = con.prepareCall("{call get_countries}");
ResultSet rs = cs.executeQuery();But I get the following exception thrown:
Exception in thread "main" java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'GET_COUNTRIES'
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:745_)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(_T4CCallableStatement.java:218_)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(_T4CCallableStatement.java:969_)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(_OracleStatement.java:1190_)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(_OraclePreparedStatement.java:3370_)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(_OraclePreparedStatement.java:3415_)
at JDBCTest.main(_JDBCTest.java:44_)
This makes no sense to me because there are no parameters that I need to pass. So I'm guessing this is something that I don't know about JDBC or about Oracle. I've searched Google for the past hour and a half and still haven't found anything that explains what might be the problem. I've also been following this guide ([http://java.sun.com/docs/books/tutorial/jdbc/basics/sql.html]) and I'm doing it exactly the same way, but for some reason it works for them.
Anyone know what I'm doing wrong?
Thanks for your help in advance. I really appreciate it!I went to a few forums and asked the same question. The boys down at Oracle Community Forums shed some light on this subject and, with their help, I was able to figure it out. Here is the thread for those who want to read: [My Thread @ Oracle Community Forums|http://forums.oracle.com/forums/thread.jspa?messageID=2721348?].
THE SOLUTION
cs = con.prepareCall("{ call get_countries(?) }");
cs.registerOutParameter(1, OracleTypes.CURSOR);
cs.execute();
ResultSet rs = ((OracleCallableStatement) cs).getCursor(1); -
Passing Ref Cursor to Oracle Stored Procedure Via C#
Hi all,
I am new to oracle and stuck with an issue. I have three insert stored procedures for three different tables. Two of them have multiple rows to be inserted, which is currently done via iterating through each row and insert to db in C# code. My requirement is to merge these three procedures in one and instead of iterating from C# code send table rows as (ref cursor or collection) to procedure and the procedure will handle the rest.
I read that ref cursor only works if you're data is in database as it reference the memory but in my case data is build on client side.
I am using Oracle 11i and ASP.Net 2.0
Can any help me on this please?
Edited by: 929463 on Apr 23, 2012 12:38 AM929463 wrote:
I am new to oracle and stuck with an issue. I have three insert stored procedures for three different tables. Two of them have multiple rows to be inserted, which is currently done via iterating through each row and insert to db in C# code. My requirement is to merge these three procedures in one and instead of iterating from C# code send table rows as (ref cursor or collection) to procedure and the procedure will handle the rest.Why a single procedure? How is the procedure to determine the target table to insert the data into? And please - no dynamic SQL as that is 99% of the time wrong.
A ref cursor is something that PL/SQL creates - with the purpose of passing the cursor handle to your code. This enables the actual SQL statement for that cursor to be moved from client code, into a PL/SQL stored proc. It abstracts the client from having to understand SQL, understand the data model and so on. All clients use the same PL/SQL proc and thus the same code for creating that cursor. Thus no issue of some clients getting it half right or half wrong and dealing with data inconsistencies between clients.
The PL/SQL proc can be tuned and optimised, modified for catering for data model changes and so on. Without your client code having to be even recompiled as it is isolated against these server changes.
For all other interaction (running PL/SQL code, doing insert/update/delete/etc SQL statements), you need to create the cursor yourself in your code.
Also, the SQL engine only sees cursors. There are no differences between cursors. The client (e.g. PL/SQL) can call it a reference cursor, or an implicit cursor, or a DBMS_SQL cursor.. the SQL engine does not know that and does not care.
A ref cursor is simply a special type of client interface to a SQL cursor, allowing PL/SQL to create that SQL cursor and then pass the handle of that SQL cursor to other code to consume that cursor.
Okay, so if you want to insert data, you need in your code to create a cursor. This can be a SQL INSERT cursor - the actual insert statement. Or it can be a PL/SQL call - an anonymous PL/SQL code block that calls a stored proc that performs the insert (after applying validation and business logic).
The cursor will have one or more bind variables. Your client will pass values for these variables and the server-side code (SQL or PL/SQL) will be executed using this as variable data.
You can for example create a cursor as follows:
begin
DoFunkyInsert( :1, :2, :3 );
end;
{code}
3 bind variables are expected. You can now in the client build an array for each of these variables, containing a 100 values each (total of a 100 rows to insert). Do a single execute of the cursor, and tell Oracle that the bind is actually a 100 element array.
The complete array ships to Oracle - Oracle opens a loop and execute the cursor for each element in the array.
This is called bulk binding.
An alternative approach is to define the bind variable as a collection (a non-scalar value). And then code the PL/SQL procedure to open a loop and iterate through the collection/array, inserting a row per iteration.
The binding itself is more complex as your code know needs to understand Oracle object types and be able to define an array/collection that is a valid Oracle non-scalar data type.
The +Oracle Call Interface+ (OCI) is quite flexible in this regard. However, as you work via an abstraction layer (e.g. ADO, OleDB, ODBC, etc) your code is subject to whatever functionality this abstraction layer makes available to your code. And this is seldom includes all the power, functionality and flexibility of the (more complex) OCI itself. -
Can we pass the HashMap object to Stored procedure using toplink
Can we send the java.util.Map object as input to the stored procedures.
Can any one please tell how we can do this using toplink.
I tried to do that by doing following steps
1. Crated the
-- Column Name - Value Pair
CREATE TYPE col_data_pair IS OBJECT (column_name varchar2(50), data VARCHAR2(32767))
2. create or replace PROCEDURE XL_MAP_TEST (poData In COL_DATA_PAIR) as
v_timestamp TIMESTAMP;
BEGIN
INSERT INTO RECON_ATTR_UD_TFCHILD(RECON_TABLE_KEY, RE_KEY, RECON_UD_TESTFORM_KEY,RECON_UD_TFCHILD_GROUP)
values (RECON_TABLE_KEY_SEQ.NEXTVAL,15, 25 ,'Persistentss23');
END XL_MAP_TEST;
3. .
[junit] Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 080121)): oracle.toplink.exceptions.DatabaseException
[junit] Internal Exception: java.sql.SQLException: Invalid column type
[junit] Error Code: 17004
[junit] Call: BEGIN XL_MAP_TEST(?); END;
[junit] bind => [null => poData]
[junit] Query: ValueReadQuery()
[junit] at oracle.toplink.exceptions.DatabaseException.sqlException(DatabaseException.java:304)
[junit] at oracle.toplink.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:613)
[junit] at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:467)
[junit] at oracle.toplink.threetier.ServerSession.executeCall(ServerSession.java:447)
[junit] at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
[junit] at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:179)
[junit] at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:250)
[junit] at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelect(DatasourceCallQueryMechanism.java:232)
[junit] at oracle.toplink.queryframework.DirectReadQuery.executeNonCursor(DirectReadQuery.java:92)
[junit] at oracle.toplink.queryframework.DataReadQuery.executeDatabaseQuery(DataReadQuery.java:118)
[junit] at oracle.toplink.queryframework.ValueReadQuery.executeDatabaseQuery(ValueReadQuery.java:55)
[junit] at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:671)
[junit] at oracle.toplink.queryframework.DataReadQuery.execute(DataReadQuery.java:104)
[junit] at oracle.toplink.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2260)
[junit] at oracle.toplink.internal.sessions.AbstractSession.executeQuery(AbstractSession.java
[junit] Caused by: java.sql.SQLException: Invalid column type
[junit] at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
[junit] at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:110)
[junit] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:171)
[junit] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:
4. StoredProcedureCall spc = new StoredProcedureCall();
HashMap poData = new HashMap();
poData.put("d", "s");
poData.put("s", "s");
spc.setProcedureName(procedureName);
spc.addUnamedInOutputArgument("poData", "poData", Types.OTHER,
"COL_DATA_PAIR",HashMap.class);
ValueReadQuery query = new ValueReadQuery();
query.setCall(spc);
query.addArgument("poData");
Vector args = new Vector();
args.add(poData);
session.executeQuery(query, args);Hi
Thanks for your inputs. Can you please send me the code stuff how we can use ObjectRelationalDescriptor. I tried to do that by doing following steps
1. Crated one class
oracle.InputOfTypeMap poData =
new oracle.InputOfTypeMap();
poData.setKay("ddd");
poData.setValue("ddd");
2. oracle.toplink.objectrelational.ObjectRelationalDescriptor descriptor =
new oracle.toplink.objectrelational.ObjectRelationalDescriptor(); descriptor.setJavaClass(oracle.iam.reconciliation.vo.InputOfTypeMap.class);
descriptor.setStructureName("COL_DATA_PAIR");
descriptor.addFieldOrdering("column_name");
descriptor.addFieldOrdering("data");
descriptor.addDirectMapping("key", "column_name");
descriptor.addDirectMapping("value", "data");
3. I was not sure how to use this further StoredProcedureCall
Can you plese help me, how we can do that? -
Unable to get the data from ms sql stored procedures using crystal report 10
Dear,
I am using the crystal report 10 and MS SQL 2000. I created stored procedures and after making the connection, i am unbale the data from that procedure. When i run stored procedure on MS SQL server it works fine.
Please help me.
Best Regards
Pankaj
[email protected]Dear,
I am using the crystal report 10 and MS SQL 2000. I created stored procedures and after making the connection, i am unbale the data from that procedure. When i run stored procedure on MS SQL server it works fine.
Please help me.
Best Regards
Pankaj
[email protected] -
Multi-Value Parameters to Oracle Stored Procedures via SQL Commands
Hi,
When you used stored procedure in CR, you need to declare REF CURSOR, This type of cursor is a dynamic cursor not a static cursor. Hence, you are able to manipulate dataset in this type of cursor.
Regards,
Titanium0203As far as I know the documentation on CR & stored procedures says that the REF CURSOR has to be a strongly bound one.
Could you go into a little more detail? Do you mean I should put a multi-valued parameter into a REF CURSOR? Can you post some code snippets here? -
Physical Data Service to Oracle Stored Procedure Package
i'm calling a package with the following signature:
PROCEDURE QUERY_ENTITY (
P_TABLE_NAME IN VARCHAR2,
P_ENTITY_ID IN NUMBER,
P_USER IN VARCHAR2,
P_RECORDSET OUT CNODB_ENTITY_PKG.C_ENTITY);
When defining the data source what to I type the OUT parameter as? My DBA tells me that it returns a reference cursor. I've randomly chosen quite a number of things which results in the error "Relational wrapper excpetion. could not find the corresponding sql type for output parameter P_RECORDSET.
Has anyone written a Physical DS that connects to Oracle Packages that return a refernce cursor rather than a specific data type?
Sorry, here's the full dump of the error:
com.bea.dsp.das.exception.DASException: weblogic.xml.query.exceptions.XQuerySagaException: {bea-err}UPD003: Update failure: mixed outcome, update error dispatched (updateid=SAGA_64f908a41cb48aeb:51ff32b4:1233d8ca55c:-7fdb): com.bea.dsp.wrappers.rdb.exceptions.RDBWrapperException: {bea-err}RDBW0000: Relational wrapper exception. could not find the corresponding sql type for output parameter P_RECORDSET
at com.bea.dsp.das.ejb.EJBClient.invokeOperation(EJBClient.java:160)
at com.bea.dsp.das.DataAccessServiceImpl.invokeOperation(DataAccessServiceImpl.java:171)
at com.bea.dsp.das.DataAccessServiceImpl.invoke(DataAccessServiceImpl.java:122)
at com.bea.dsp.ide.xquery.views.test.QueryExecutor.invokeFunctionOrProcedure(QueryExecutor.java:113)
at com.bea.dsp.ide.xquery.views.test.XQueryTestViewContent.getFunctionExecutionResult(XQueryTestView.java:1041)
at com.bea.dsp.ide.xquery.views.test.XQueryTestViewContent.executeFunction(XQueryTestView.java:1176)
at com.bea.dsp.ide.xquery.views.test.XQueryTestViewContent.widgetSelectedImpl(XQueryTestView.java:1866)
at com.bea.dsp.ide.xquery.views.test.XQueryTestViewContent.access$300(XQueryTestView.java:174)
at com.bea.dsp.ide.xquery.views.test.XQueryTestViewContent$3.run(XQueryTestView.java:1594)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
at com.bea.dsp.ide.xquery.views.test.XQueryTestViewContent.widgetSelectedBusy(XQueryTestView.java:1597)
at com.bea.dsp.ide.xquery.views.test.XQueryTestViewContent.widgetSelected(XQueryTestView.java:1560)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:227)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3687)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3298)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:508)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
at org.eclipse.equinox.launcher.Main.eclipse_main(Main.java:1148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.m7.installer.util.NitroxMain$1.run(NitroxMain.java:33)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: weblogic.xml.query.exceptions.XQuerySagaException: {bea-err}UPD003: Update failure: mixed outcome, update error dispatched (updateid=SAGA_64f908a41cb48aeb:51ff32b4:1233d8ca55c:-7fdb): com.bea.dsp.wrappers.rdb.exceptions.RDBWrapperException: {bea-err}RDBW0000: Relational wrapper exception. could not find the corresponding sql type for output parameter P_RECORDSET
at com.bea.ld.server.update.recovery.SagaRecovery.process(SagaRecovery.java:104)
at com.bea.ld.server.update.recovery.DSPSagaManager.processSagaFailure(DSPSagaManager.java:222)
at weblogic.xml.query.update.recovery.SagaState$2.afterCompletion(SagaState.java:87)
at weblogic.xml.query.transaction.TransactionManager.afterCompletion(TransactionManager.java:134)
at weblogic.transaction.internal.ServerSCInfo.doAfterCompletion(ServerSCInfo.java:1032)
at weblogic.transaction.internal.ServerSCInfo.callAfterCompletions(ServerSCInfo.java:1011)
at weblogic.transaction.internal.ServerTransactionImpl.callAfterCompletions(ServerTransactionImpl.java:2990)
at weblogic.transaction.internal.ServerTransactionImpl.afterRolledBackStateHousekeeping(ServerTransactionImpl.java:2871)
at weblogic.transaction.internal.ServerTransactionImpl.setRolledBack(ServerTransactionImpl.java:2847)
at weblogic.transaction.internal.ServerTransactionImpl.globalRetryRollback(ServerTransactionImpl.java:3087)
at weblogic.transaction.internal.ServerTransactionImpl.globalRollback(ServerTransactionImpl.java:2837)
at weblogic.transaction.internal.ServerTransactionImpl.internalRollback(ServerTransactionImpl.java:400)
at weblogic.transaction.internal.ServerTransactionImpl.rollback(ServerTransactionImpl.java:378)
at weblogic.xml.query.transaction.TransactionHelper.rollback(TransactionHelper.java:102)
at weblogic.xml.query.transaction.TransactionManager.teardownOnFailure(TransactionManager.java:264)
at com.bea.ld.EJBRequestHandler.handleThrowable(EJBRequestHandler.java:829)
at com.bea.ld.EJBRequestHandler.invokeOperation(EJBRequestHandler.java:326)
at com.bea.ld.ServerBean.executeOperationStreaming(ServerBean.java:84)
at com.bea.ld.Server_ydm4ie_EOImpl.executeOperationStreaming(Server_ydm4ie_EOImpl.java:426)
at com.bea.ld.Server_ydm4ie_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473)
at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: com.bea.dsp.wrappers.rdb.exceptions.RDBWrapperException: {bea-err}RDBW0000: Relational wrapper exception. could not find the corresponding sql type for output parameter P_RECORDSET
at com.bea.dsp.wrappers.rdb.exceptions.RDBWrapperException.create(RDBWrapperException.java:89)
at weblogic.xml.query.exceptions.XQueryException.create(XQueryException.java:127)
at weblogic.xml.query.exceptions.XQueryException.create(XQueryException.java:87)
at weblogic.xml.query.exceptions.XQueryException.create(XQueryException.java:151)
at weblogic.xml.query.exceptions.XQueryException.create(XQueryException.java:139)
at com.bea.dsp.wrappers.rdb.runtime.ProcedureCallableWrapper.prepareQuery(ProcedureCallableWrapper.java:272)
at com.bea.dsp.wrappers.rdb.runtime.ProcedureIterator.getNextToken(ProcedureIterator.java:175)
at com.bea.dsp.wrappers.rdb.runtime.ProcedureIterator.fetchNext(ProcedureIterator.java:125)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:104)
at weblogic.xml.query.runtime.core.ExecutionWrapper.fetchNext(ExecutionWrapper.java:88)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:104)
at weblogic.xml.query.runtime.util.TokenBuffer.addAll(TokenBuffer.java:368)
at weblogic.xml.query.update.runtime.Interpreter$Frame.setValueUsingTemporary(Interpreter.java:429)
at weblogic.xml.query.update.runtime.Interpreter.processMSet(Interpreter.java:271)
at weblogic.xml.query.update.runtime.Interpreter.run(Interpreter.java:108)
at weblogic.xml.query.update.rewriting.UVMUtils$3.run(UVMUtils.java:130)
at weblogic.xml.query.update.recovery.SagaInterpreter.run(SagaInterpreter.java:41)
at weblogic.xml.query.update.runtime.UVMRewritingEvaluatorImpl.run(UVMRewritingEvaluatorImpl.java:32)
at weblogic.xml.query.xdbcimpl.XQSEStatementImpl.execute(XQSEStatementImpl.java:103)
at com.bea.ld.server.XQueryInvocation.execute(XQueryInvocation.java:752)
at com.bea.ld.EJBRequestHandler.invokeQueryInternal(EJBRequestHandler.java:624)
at com.bea.ld.EJBRequestHandler.invokeOperationInternal(EJBRequestHandler.java:478)
at com.bea.ld.EJBRequestHandler.invokeOperation(EJBRequestHandler.java:323)
... 12 more
Edited by: user10592709 on Aug 21, 2009 11:41 AMFirst (and somewhat unrelated) - how come the "update" errors? Aren't you just trying to read it? You should probably be using "function" instead of "procedure" in your dataservice. You should only be using procedure (XQSE) if you are updating. Not that this is related to your problem - it's just something you should know.
Now for the REF CURSOR. You need to figure out what columns are being returned, and then define a schema to match, then use that schema as the definition. If you are lucky, the REF CURSOR will actually be a cursor from selecting on a table. If that is the case, you can create a new physical data service based on that table - which will result in a schema being created with the same name as the table. Then create a new physical data service based on the stored procudure, the type of that parameter should appear as "Unknown". Edit the parameter types and specify the type in the schema that was generated for the table.
Maybe you are looking for
-
ITunes does not recognise USB Flash Drive
Hi everyone, I am repeating this request in the hopes that the daytime crowd will have someone who can help! I plug a usb flashdrive into my MacBook with iTunes active. It comes up on desktop. It does not appear as device in iTunes. I can move files
-
Hello All, I have a blob column on a table that has been used to store xml files. I would like to pull out all these files and load them into a table with an xmltype column. I have been trying to use dbms_lob to write a function that converts blob to
-
Threading two different text boxes
Hi.. How do you thread two different text box with two different text format? Eg. Text Box 1: Font Size 50pt... Text box 2: Font Size 10pt.. Once you thread the two text boxes; and delete the content in Text box 1, what ever the content that flows to
-
Processing in Warehouse timed out; processing steps mising
Hi All, Recently i am getting error Processing in warehouse timed out When iam loading the Master data from flat file to BW . Inspite of loading many times getting the same error. Earlier it was perfect. What are the possible reasons for the same? C
-
5 Different movies have been deleted from my Itunes account. They have been purchased and downloaded to my Ipad. I cannot watch them on my desktop that I used to download them in the first place. This has just happened over the last week. How can I R