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 AM
929463 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.
Similar Messages
-
Problem passing REF CURSOR to JAVA STORED PROCEDURE
Hi,
I've written a small Java class with a static method and
imported that into Oracle 8i. The method expects a
java.sql.ResultSet object as parameter. According to the
documentation of Oracle, a REF CURSOR (cursor variable) maps to
java.sql.ResultSet in JDBC.
The definition of the Java Stored Procedure was accepted without
problems:
CREATE OR REPLACE PROCEDURE RESULTSETPASSINGTESTPROC (row
WASTypes.GenericCurType)
as language java
name 'sqlj.ResultSetPassingTest.testResultSetPassing
(java.sql.ResultSet)';
WASTypes is a package containing the definition of the generic
cursor:
CREATE OR REPLACE PACKAGE WASTYPES
is
TYPE GenericCurType IS REF CURSOR;
END WASTypes;
In a function I'm opening the cursor via
'Open cursorVariable for sqlStatement';
Then this cursor variable is passed to the java method and the
error ORA-03113 is shown.
I tried to solve the problem by changing the type of the
parameter to oracle.sql.REF without success.
Does anybody know what wents wrong?
Thanks in advance.
JanHi,
I've written a small Java class with a static method and
imported that into Oracle 8i. The method expects a
java.sql.ResultSet object as parameter. According to the
documentation of Oracle, a REF CURSOR (cursor variable) maps to
java.sql.ResultSet in JDBC.
The definition of the Java Stored Procedure was accepted without
problems:
CREATE OR REPLACE PROCEDURE RESULTSETPASSINGTESTPROC (row
WASTypes.GenericCurType)
as language java
name 'sqlj.ResultSetPassingTest.testResultSetPassing
(java.sql.ResultSet)';
WASTypes is a package containing the definition of the generic
cursor:
CREATE OR REPLACE PACKAGE WASTYPES
is
TYPE GenericCurType IS REF CURSOR;
END WASTypes;
In a function I'm opening the cursor via
'Open cursorVariable for sqlStatement';
Then this cursor variable is passed to the java method and the
error ORA-03113 is shown.
I tried to solve the problem by changing the type of the
parameter to oracle.sql.REF without success.
Does anybody know what wents wrong?
Thanks in advance.
Jan -
How to get an UPDATABLE REF CURSOR from the STORED PROCEDURE
using C# with
ORACLE OLE DB version: 9.0.0.1
ADO version: 2.7
I returns a REF CURSOR from a stored procedure seems like:
type TCursor is ref cursor;
procedure test_out_cursor(p_Dummy in varchar, p_Cur out TCursor) is
begin
open p_Cur for select * from DUAL;
end;
I create an ADO Command object and set
cmd.Properties["IRowsetChange"].Value = true;
cmd.Properties["Updatability"].Value = 7;
cmd.Properties["PLSQLRSet"].Value = 1;
cmd.CommandText = "{CALL OXSYS.TEST.TEST_OUT_CURSOR(?)}";
and I use a Recordset object to open it:
rs.Open(cmd, Missing.Value,
ADODB.CursorTypeEnum.adOpenStatic,
ADODB.LockTypeEnum.adLockBatchOptimistic,
(int) ADODB.CommandTypeEnum.adCmdText +
(int) ADODB.ExecuteOptionEnum.adOptionUnspecified);
The rs can be opened but can NOT be updated!
I saved the recordset into a XML file and there's no
rs:baseschema/rs:basetable/rs:basecolumn
attributes for "s:AttributeType" element.
Any one have idea about this?
thanks very muchIt is not possible through ADO/OLEDB.
Try ODP.NET currently in Beta, it is possible to update DataSet created with refcursors. You need to specify your custom SQL or SP to send update/insert/delete.
As I remember there is a sample with ODP.NET Beta 1 just doing this. -
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 tipsAs 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? -
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. -
Ref Cursors in a stored Procedure
Can some help me with an answer to the below question.
How many ref cursors can be declared in a stored procedure in oracle?
Thanksuser533016 wrote:
You are right. Keeping so many cursors open is not good at all. But i was doing this to see where it breaks and is there something that definitely controls the number of refcursors in allowed a PL/SQL block.As Karthick already mentioned you have the OPEN_CURSORS parameter which defines how many open cursors you may have in any one session.
However, this doesn't just apply to Ref Cursors. If you open explicitly defined cursors then this will also count towards that, as well as issuing select statements as they are implicit cursors... e.g.
declare
cursor c1 is
select * from emp;
cursor c2 is
select * from dept;
v_c1 c1%ROWTYPE;
v_c2 c2%ROWTYPE;
v_cnt number;
begin
open c1; -- now we have 1 open cursors
loop
fetch c1 into v_c1;
exit when c1%notfound;
open c2; -- now we have 2 open cursors
loop
fetch c2 into v_c2;
exit when c2%notfound;
select count(*) -- this counts as opening cursor number 3.
into v_cnt
from payroll;
-- after the select statement the implicit cursor is automatically closed, so now we have 2 open again
end loop;
close c2; -- after this we just have 1 more open
end loop;
close c1; -- after this we have no open cursors
end; -
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? -
REF CURSOR RETURNED FROM STORED PROCEDURE OPENED WITH CURRENT_USER PRIVILEGES
Hi.
I was wondering if anyone knows when this bug will be fixed. The bug# is 899567 off of metalink.
I am running into this problem as well, and we do not want to use OCI/SQLNet as the fix. We have an application with secure data concerns and only want to give access to stored procedures to an application user.
Thanks,
BradI'm using version 8.1.6.0.0 on a W2K server.
PS: a strange behaveour
if i try to insert a row using the following anonymous pl/sql block
begin
insert into objects select 2, 'B', ref(c) from meta.classes c where id =1;
end;
i get the following error msg
ERROR at line 1:
ORA-06552: PL/SQL: Compilation unit analysis terminated
ORA-06553: PLS-302: component 'OBJ_T' must be declared
but if i use only the sql command from the sql plus prompt
insert into objects select 2, 'B', ref(c) from meta.classes c where id =1;
the row is inserted.
OBJ_T is the object type(id number, label varchar2, class ref class_t),
OBJECTS is a table of obj_t,
CLASS_T is an object type(id number, label varchar2)
CLASSES is a table of CLASS_T.
null -
Pass a list to Oracle Stored procedure
I would like to pass a string as an input parameter to a Oracle procedure.I would then like to use this string as an "IN" clause in my select statement
Eg.select deptno from emp where empno in (ip_parameter)
However if I give the ip_parameter='7,8,9' I get an 'Invalid Number' error.
Can somebody please help----Not sure if this is what you mean but . . .
PROCEDURE test (p_emp_nos VARCHAR2) is
TYPE emp_nos_table IS TABLE OF VARCHAR2(4) INDEX BY BINARY_INTEGER;
emp_nos emp_nos_table;
i_pos INTEGER := 1;
i_comma INTEGER;
BEGIN
i_comma := INSTR(p_emp_nos,',',i_pos);
WHILE i_comma > 0 LOOP
emp_nos(emp_nos.COUNT+1) := SUBSTR(p_emp_nos,i_pos,i_comma-i_pos);
i_pos := i_comma + 1;
i_comma := INSTR(p_emp_nos,',',i_pos);
END LOOP;
emp_nos(emp_nos.COUNT+1) := SUBSTR(p_emp_nos,i_pos);
dbms_output.put_line (TO_CHAR(emp_nos.COUNT) || ' emp nos in ' || p_emp_nos);
FOR i IN 1 .. emp_nos.COUNT LOOP
dbms_output.put_line ('emp no ' || TO_CHAR(i) || ' = ' || emp_nos(i));
END LOOP;
END test; -
Create Oracle BLOB and Pass to Oracle Stored Procedure
Hi All,
I am using Oracle 10g and am dealing with a requirement where I have to upload a file to Oracle Portal from the client's local machine using a JSP.
I am planning to convert the text file to a BLOB and pass it to an Oracle stored procedure which does the rest.
I am unable to create a BLOB object. Can anybody help me with this please.
Is there a better alternative to do it?
Thanks in advance,
Shardulu can create blob as below...
java.sql.Blob blob=new Blob();
File file=new File(fullPathTo UrFile);
FileInputStream fInSteam = new FileInputStream(file);
BufferedInputStream bInputStream = new BufferedInputStream(fInSteam);
ByteArrayOutputStream bOutputStream = new ByteArrayOutputStream();
int nextByte;
while (( nextByte = bInputStream.read() ) != - 1)
bOutputStream.write(nextByte);
byte[] byteContent = bOutputStream.toByteArray();
blob.setBytes(byte[]);
i think it should work for u... -
Passing Tables back from Java Stored Procedures
Thomas Kyte has written (in reference to
trying to pass an array back from a stored
function call):
You can do one of two things (and both require the use of
objects). You cannot use PLSQL table types as JDBC cannot bind to
this type -- we must use OBJECT Types.
[snip]
Another way is to use a result set and "select * from
plsql_function". It could look like this:
ops$tkyte@8i> create or replace type myTableType as table of
varchar2 (64);
2 /
Type created.
ops$tkyte@8i>
ops$tkyte@8i>
ops$tkyte@8i> create or replace
2 function demo_proc2( p_rows_to_make_up in number )
3 return myTableType
4 as
5 l_data myTableType := myTableType();
6 begin
7 for i in 1 .. p_rows_to_make_up
8 loop
9 l_data.extend;
10 l_data(i) := 'Made up row ' | | i;
11 end loop;
12 return l_data;
13 end;
14 /
Function created.
ops$tkyte@8i>
ops$tkyte@8i> select *
2 from the ( select cast( demo_proc2(5) as mytableType )
3 from dual );
COLUMN_VALUE
Made up row 1
Made up row 2
Made up row 3
Made up row 4 [Image]
Made up row 5
So, your JDBC program would just run the query to get the data.
If the function "demo_proc2" cannot be called from SQL for
whatever reason (eg: it calls an impure function in another piece
of code or it itself tries to modify the database via an insert
or whatever), you'll just make a package like:
ops$tkyte@8i> create or replace package my_pkg
2 as
3
4 procedure Make_up_the_data( p_rows_to_make_up in
number ); 5 function Get_The_Data return myTableType;
6 end;
7 /
Package created.
ops$tkyte@8i>
ops$tkyte@8i> create or replace package body my_pkg
2 as
3
4 g_data myTableType;
5
6 procedure Make_up_the_data( p_rows_to_make_up in number )
7 as
8 begin
9 g_data := myTableType();
10 for i in 1 .. p_rows_to_make_up
11 loop
12 g_data.extend;
13 g_data(i) := 'Made up row ' | | i;
14 end loop;
15 end;
16
17
18 function get_the_data return myTableType
19 is
20 begin
21 return g_data;
22 end;
23
24 end;
25 /
Package body created.
ops$tkyte@8i>
ops$tkyte@8i> exec my_pkg.make_up_the_data( 3 );
PL/SQL procedure successfully completed.
ops$tkyte@8i>
ops$tkyte@8i> select *
2 from the ( select cast( my_pkg.get_the_data as mytableType
) 3 from dual );
COLUMN_VALUE
Made up row 1
Made up row 2
Made up row 3
And you'll call the procedure followed by a query to get the
data...
I have tried this, and it works perfectly.
My question, is what does the wrapper look
like if the stored function is written
in java instead of PL/SQL? My experiments
with putting the function in java have been
dismal failures. (I supposed I should also
ask how the java stored procedure might
look also, as I suppose that could be where
I have been having a problem)
nullThanks for the response Avi, but I think I need to clarify my question. The articles referenced in your link tended to describe using PL/SQL ref cursors in Java stored procedures and also the desire to pass ref cursors from Java to PL/SQL programs. Unfortunately, what I am looking to do is the opposite.
We currently have several Java stored procedures that are accessed via select statements that have become a performance bottleneck in our system. Originally the business requirements were such that only a small number of rows were ever selected and passed into the Java stored procedures. Well, business requirements have changed and now thousands and potentially tens of thousands of rows can be passed in. We benchmarked Java stored procedures vs. PL/SQL stored procedures being accessed via a select statement and PL/SQL had far better performance and scaleable. So, our thought is by decouple the persistence logic into PL/SQL and keeping the business logic in Java stored procedures we can increase performance without having to do a major rewrite of the existing code. This leads to the current problem.
What we currently do is select into a Java stored procedure which has many database access calls. What we would like to do is select against a PL/SQL stored procedure to aggregate the data and then pass that data via a ref cursor (or whatever structure is acceptable) to a Java stored procedure. This would save us a significant amount of work since the current Java stored procedures would simple need to be changed to not make database calls since the data would be handed to them.
Is there a way to send a ref cursor from PL/SQL as an input parameter to a Java stored procedure? My call would potentially look like this:
SELECT java_stored_proc(pl/sql_stored_proc(col_id))
FROM table_of_5000_rows;
Sorry for the lengthy post. -
Call to Oracle stored procedure that returns ref cursor doesn't work
I'm trying to use an OData service operation with Entity Framework to call an Oracle stored procedure that takes an number as an input parameter and returns a ref cursor. The client is javascript so I'm using the rest console to test my endpoints. I have been able to successful call a regular Oracle stored procedure that takes a number parameter but doesn't return anything so I think I have the different component interactions correct. When I try calling the proc that has an ref cursor for the output I get the following an error "Invalid number or type of parameters". Here are my specifics:
App.config
<oracle.dataaccess.client>
<settings>
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursor.P_RESULTS" value="implicitRefCursor bindinfo='mode=Output'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.0" value="implicitRefCursor metadata='ColumnName=WINDFARM_ID;BaseColumnName=WINDFARM_ID;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Number;ProviderType=Int32'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.1" value="implicitRefCursor metadata='ColumnName=STARTTIME;BaseColumnName=STARTTIME;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.2" value="implicitRefCursor metadata='ColumnName=ENDTIME;BaseColumnName=ENDTIME;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.3" value="implicitRefCursor metadata='ColumnName=TURBINE_NUMBER;BaseColumnName=TURBINE_NUMBER;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.4" value="implicitRefCursor metadata='ColumnName=NOTES;BaseColumnName=NOTES;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYWINDFARMID.RefCursorMetaData.P_RESULTS.Column.5" value="implicitRefCursor metadata='ColumnName=TECHNICIAN_NAME;BaseColumnName=TECHNICIAN_NAME;BaseSchemaName=PGDATA_WC;BaseTableName=WORKORDERS;NATIVEDATATYPE=Varchar2;ProviderType=Varchar2'" />
<add name="PGDATA_WC.ODATAPOC.GETWORKORDERSBYID.RefCursor.P_RESULTS" value="implicitRefCursor bindinfo='mode=Output'" />
</settings>
OData Service Operation:
public class OracleODataService : DataService<OracleEntities>
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("GetWorkOrdersByWindfarmId", ServiceOperationRights.All);
config.SetServiceOperationAccessRule("CreateWorkOrder", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
[WebGet]
public IQueryable<GetWorkOrdersByWindfarmId_Result> GetWorkOrdersByWindfarmId(int WindfarmId)
return this.CurrentDataSource.GetWorkOrdersByWindfarmId(WindfarmId).AsQueryable();
[WebGet]
public void CreateWorkOrder(int WindfarmId)
this.CurrentDataSource.CreateWorkOrder(WindfarmId);
Here is the stored procedure:
procedure GetWorkOrdersByWindFarmId(WINDFARMID IN NUMBER,
P_RESULTS OUT REF_CUR) is
begin
OPEN P_RESULTS FOR
select WINDFARM_ID,
STARTTIME,
ENDTIME,
TURBINE_NUMBER,
NOTES,
TECHNICIAN_NAME
from WORKORDERS
where WINDFARM_ID = WINDFARMID;
end GetWorkOrdersByWindFarmId;
I defined a function import for the stored procedure using the directions I found online by creating a new complex type. I don't know if I should be defining the input parameter, WindfarmId, in my app.config? If I should what would that format look like? I also don't know if I'm invoking the stored procedure correctly in my service operation? I'm testing everything through the rest console because the client consuming this information is written in javascript and expecting a json format. Any help is appreciated!
Edited by: 1001323 on Apr 20, 2013 8:04 AM
Edited by: jennyh on Apr 22, 2013 9:00 AMMaking the change you suggested still resulted in the same Oracle.DataAccess.Client.OracleException {"ORA-06550: line 1, column 8:\nPLS-00306: wrong number or types of arguments in call to 'GETWORKORDERSBYWINDFARMID'\nORA-06550: line 1, column 8:\nPL/SQL: Statement ignored"} System.Exception {Oracle.DataAccess.Client.OracleException}
I keep thinking it has to do with my oracle.dataaccess.client settings in App.Config because I don't actually put the WindfarmId and an input parameter. I tried a few different ways to do this but can't find the correct format. -
Passing Arrays of User Defined Types to Oracle Stored Procedures
Hi
I am using WebLogic 8.14 & Oracle 9i with thin JDBC driver.
Our application needs to perform the same DB operation for every item in a Java Collection. I cannot acheive the required performance using the standard Prepare & Execute loop and so I am looking to push the whole collection to Oracle in a single invocation of a Stored Procedure and then loop on the database.
Summary of Approach:
In the Oracle database, we have defined a Object Type :
CREATE OR REPLACE
TYPE MYTYPE AS OBJECT
TxnId VARCHAR2(40),
Target VARCHAR2(20),
Source VARCHAR2(20),
Param1 VARCHAR2(2048),
Param2 VARCHAR2(2048),
Param3 VARCHAR2(2048),
Param4 VARCHAR2(2048),
Param5 VARCHAR2(2048),
and we have defined a collection of these as:
CREATE OR REPLACE
TYPE MYTYPE_COLLECTION AS VARRAY (100) OF MYTYPE
There is a stored procedure which takes one of these collections as an input parameter and I need to invoke these from within my code.
I am having major problems when I attempt to get the ArrayDescriptor etc to allow me to create an Array to pass to the stored procedure. I think this is because the underlying Oracle connection is wrapped by WebLogic.
Has anyone managed to pass an array to an Oracle Stored procedure on a pooled DB connection?
Thanks
AndyAndy Bowes wrote:
Hi
I am using WebLogic 8.14 & Oracle 9i with thin JDBC driver.
Our application needs to perform the same DB operation for every item in a Java Collection. I cannot acheive the required performance using the standard Prepare & Execute loop and so I am looking to push the whole collection to Oracle in a single invocation of a Stored Procedure and then loop on the database.
Summary of Approach:
In the Oracle database, we have defined a Object Type :
CREATE OR REPLACE
TYPE MYTYPE AS OBJECT
TxnId VARCHAR2(40),
Target VARCHAR2(20),
Source VARCHAR2(20),
Param1 VARCHAR2(2048),
Param2 VARCHAR2(2048),
Param3 VARCHAR2(2048),
Param4 VARCHAR2(2048),
Param5 VARCHAR2(2048),
and we have defined a collection of these as:
CREATE OR REPLACE
TYPE MYTYPE_COLLECTION AS VARRAY (100) OF MYTYPE
There is a stored procedure which takes one of these collections as an input parameter and I need to invoke these from within my code.
I am having major problems when I attempt to get the ArrayDescriptor etc to allow me to create an Array to pass to the stored procedure. I think this is because the underlying Oracle connection is wrapped by WebLogic.
Has anyone managed to pass an array to an Oracle Stored procedure on a pooled DB connection?
Thanks
AndyHi. Here's what I suggest: First please get the JDBC you want to work in a
small standalone program that uses the Oracle thin driver directly. Once
that works, show me the JDBC code, and I will see what translation if
any is needed to make it work with WLS. Will your code be running in
WebLogic, or in an external client talking to WebLogic?
Also, have you tried the executeBatch() methods to see if you can
get the performance you want via batches?
Joe -
Passing array to oracle stored procedure in VC++ 2005
Hi,
I am try to send an array of integers to a stored procedure via ODBC 10.2.0.3 on VC++2005 enviornment. I get the below error
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'MYPROC1'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored ... Error Code = 6550
[]E R R O R
The same code works if I use an INSERT statement.
SQLUSMALLINT* rowsProcessed = new SQLUSMALLINT;
RETCODE nRetCode;
const int arraySize = 200;
long ptrVal[arraySize];
long ptrInd[arraySize];
long ptrStatus[arraySize];
for (int i = 0; i < arraySize; i++)
ptrVal = i;
ptrInd = 0;
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
// assign the number of sets of parameters that are to be inserted
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)iSizeOfArray, 0);
// assign an array to retrieve status info for each row of parameter values
nRetCode =SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_STATUS_PTR, (SQLPOINTER)ptrStatus, 0);
// assign a buffer to store the number of sets of parameters that have been processed
nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, (SQLPOINTER)rowsProcessed, 0);
nRetCode = SQLBindParameter(m_hstmt, nParamIndex, nDirection, SQL_C_LONG, SQL_INTEGER, 0, 0, ptrVal, 0, ptrInd);
//suceeds
SQLPrepare(m_hstmt, (SQLCHAR*)"INSERT INTO my_table VALUES (?)", SQL_NTS);
//fails
SQLPrepare(m_hstmt, (SQLCHAR*)"{CALL mypackage.myproc1(?)}", SQL_NTS);
SQLExecute(m_hstmt);
package is
create or replace package mypackage
as
type mytable is table of binary_integer;
procedure myproc1( l_tab in mytable);
end;
show errors
create or replace package body mypackage
as
procedure myproc1( l_tab in mytable)
as
begin
insert into my_table values (100);
commit;
FORALL i IN l_tab.first .. l_tab.last
INSERT into my_table values( l_tab(i) );
end;
end;
any ideas?I 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 -
Not able to get Oracle stored procedure return value passed to Powerbuilder
I have an Oracle Stored Procedure that receives a string value and returns a string value.. When I call it from Powerbuilder, it executes but does not send the return value of a string back. I am trying to encrypt a string in Powerbuilder, pass it to a .net web page and then decrypt so I can check the security tables for permissions to view the web page. I have tried creating a simple stored procedure that takes a string and returns a string to Powerbuilder; but even that is not working. Any suggesstions?
Oracle Procedure:
CREATE OR REPLACE
PROCEDURE TESTINOUT_VARCHAR
( P_STRING IN VARCHAR2, P_OUT OUT VARCHAR2)
IS
BEGIN
P_OUT := P_STRING || 'TESTING';
END TESTINOUT_VARCHAR;
Powerbuilder Call:
string p_string =' '
Declare TestingString procedure for TESTINOUT_VARCHAR(:ls_group, :p_out) using SQLCA
Execute TestingString;
IF SQLCA.CODE = 0 THEN
FETCH TestingString into:p_out;
End If
p_string = p_out;Hello John,
I'm not sure if you already found a solution using an ODBC connection.
Below the solution with an RPC call:
Create a user object (uo_trans) of type transaction with the following local external function:
subroutine TESTINOUT_VARCHAR(string P_STRING,ref string P_OUT) RPCFUNC
Execute this script
uo_trans l_transaction
string ls_outparam
l_transaction = CREATE uo_trans
// Profile ODBC_ORA
l_transaction.DBMS = "ODBC"
l_transaction.AutoCommit = False
l_transaction.DBParm = "ConnectString='DSN=ODBC_ORA;UID=system;PWD=<xxxxxx>'"
connect using l_transaction;
ls_outparam = space (30)
l_transaction.testinout_varchar( sle_1.text, ls_outparam)
messagebox("OUT parameter", ls_outparam)
disconnect using l_transaction;
DESTROY l_transaction
Maybe you are looking for
-
WIJ 20002 error on long running reports
When trying to run a long running report, an error message is received . Quote: *"The Web Intelligence Java Report Panel cannot connect to the server. Close the report panel and try to connect again or see your BusinessObjects administrator. (Error:
-
A problem with my ipod shuffle and vista
Hello all, was wondering if anyone could offer some ideas on this. My flat mate just moved and I was using his mac for my ipod shuffle. I have just bought a Dell with windows vista and have put itunes on it. When I put my ipod in the USB port, vista
-
Hi All, We are trying to change the fiscal year in asset accouting to 2010 but cannot do it. fiscal year 2008 in asset accounting is still open and cannot close it, when trying to close 2008 system give error message as "Depreciation not posted compl
-
When I type in info in Get Info it comes out in Chinese ; how do I convert to plain english?
-
Any help? Genius bar was stumped. I reinstalled mt. lion, but it still persists. Thanks.