Passing an array of structures to an Oracle stored procedure (CFMX)
I'm looking to write a Oracle stored procedure where I would pass in an array of structures and loop over each iteration to insert the bits and pieces within the structures to the DB.,
I haven't written this type of procedure / package before. I am planning to do an sp / package similar to what is sketched out in the second reply to this thread: http://forums.oracle.com/forums/thread.jspa?threadID=1078772
Assuming I do, how can I call the procedure from ColdFusion (I'm using MX) and pass in my array? As far as I can see, none of the CF_SQL_Types make sense.
Let me know if you make any progress. I'm fighting the same battle. What I've done so far is to convert my array of struct into a delimited CLOB that looks like this:
prop1;prop2;prop3|prop1;prop2;prop3|prop1;prop2;prop3|prop1;prop2;prop3|
Then I wrote a stored proc to suck it up using a pipelined function. It's not to bad but parsing the CLOB on the ORACLE side is somewhat time consuming.
I've also converted the array to XML and used dbms_xmlstore to convert but, on large arrays, it is very slow and the CLOB gets huge fast.
I was hoping to use the cf_sql_refcursor but I can't figure out how.
Warren
Similar Messages
-
Question?? - passing 2D array as a parameter of a stored procedure
Hi,
I have been having a lot of trouble with executing a stored procedure. I'm hoping someone can help me with this:
THe stored proc. has 10 parameters, 5 IN and 5 OUT. One of these parameters coming out is a 2D array, however I"m not sure how I would be able to call the correct OCCI type coming out.
I've declared a 2D array char sample[10][10];
and then:
stmt - > registerOutParam ( 7, oracle::occi:OCCI*???, sizeof(sample);
and then :
char outarray[10][10];
out_array = stmt -> getString??? get*??
I tried just passing a string itself, but as the procedure is looking for a 2D array, the program aborts, but I'm really not sure how I can solve this...??
I'm kind of new to this subject, and I would really appreciate any help anyone can provide, with being able to pass in a 2D char array and being able to receive the outcomning data.
Thanks a lot for any help!Hi,
thank you for the link, it helped a lot....
my C++ app that calls my stored procedure does compile, however, when I execute it "Aborts". I debugged it and found that right before my
stmt->executeUpdate()
statement, it outputs "Aborts", I'm really not sure why this is aborting, are there any specific debug statements or anything I can use specific to occi so that I can trace why my program aborts right before the executeUpdate statement (also I have checked my procedure and it is compiled and valid, and all my parameter types are correct).
Does anyone have any ideas??
Any help on this matter is really appreciated... thank you -
Pass xmltype to oracle stored procedure
I need to pass an xmltype from java to an oracle stored procedure. Does anybody have any sample code to do this? I am using jdeveloper 10.1.2
Thanks
MMOracle provides several ways of passing objects to and from java to Oracle Stored Procedure.
One way is to directly create oracle.sql.STRUCT object and pass array of values to this object. Another way is to implement java.sql.SQLData or oracle.sql.ORAData interfaces in your class and pass this class to setObject function.
It is all well described in manual in chapter "Working with Oracle Object Types", there is also a lot of examples in this chapter and on the web.
http://download-uk.oracle.com/docs/cd/B19306_01/java.102/b14355/oraoot.htm - Working with Oracle Object Types
Some of the examples:
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/ObjectOracleSample/Readme.html
http://javaalmanac.com/egs/java.sql/InsertObjectOraclePreparedStatement.html -
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 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 -
Is there a way to pass an array or structure for example as parameters, in addition to a query, or multiple queries to the Report Builder in CF8? I believe this was recommended by users to be in CF8.
BrianO,
Although it's been a while, I thought I'd provide the code to do this for you. It works for me in CF8, and probably will in CF7.
Here I create a structure called My, and provide that one parameter to my CFReportParam tag.
<CFSet My = {
Client = "Client Name",
ReportDateFrom = DateFormat(ThisStartDate, DateMask),
ReportDateTo = DateFormat(ThisEndDate, DateMask),
PageHeaderImage = ImagePath & "\Logos\Page_Header.png",
WatermarkImage = ImagePath & "\Logos\Watermark.png",
GetBarSummary = GetBarSummary,
GetPieSummary = GetPieSummary
}>
<CFReport Template="#ReportPath#\SpendSummary.cfr" Format="PDF" Query="GetSummary">
<CFReportParam Name="My" Value="#My#">
</CFReport>
Inside the report itself, reference the given parameter as Param.My.PageHeaderImage for example. It can be referenced that way from any expression inside the report builder. You can even use the queries as the data source for charts (using the Data From a Query -> Query Builder -> Advanced) by entering "Param.My.GetPieSummary" where it says "Variable containing query object".
HTH
Swift -
Passing arrays to Oracle Stored procedure.
Have any body passed arrays to Oracle stored procedures while the app is running in Weblogic app server. I am able to pass the arrays with regular JDBC connection. If I run the same piece of code using a connection recieved from the datasource of weblogic server, its not working. I am getting serialization errors with the ArrayDescriptor class. Looks like the ArrayDescriptor is not serializable.
Does anybody know solution/workaround to pass arrays ?
Thanks in advanceyou could write a wrapper class that extends ArrayDescriptor and implements serializable...
for example your class would look something like this.
public class MyArrayDescriptor extends ArrayDescriptor
implements Serializable
in your regular code use the wrapper class in place of the ArrayDescriptor (it will contain all the same methods as the real ArrayDescriptor) and you should be able to toss your wrapper class anywhere you please. -
Passing array to Oracle stored procedure
Is it possible to pass an array (TYPES.Array) to an oracle stored procedure in WLI? I know it can be done in vanilla jdbc.
I have tried to do this but I'm getting this exception:
java.sql.SQLException: Fail to convert to internal representation:Well well well......I was able to fix the same.
The implementation for writeSQL is the catch. We need to give the conversion only in that.
Anyway, thanks. -
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 -
How to Pass parameters to Crystal report 10 based on Oracle Stored Procedur
Hi,
I use the following code to pass the parameters:
Rep.Tables[0].ConnectBuffer := Connection_Str;
Rep.Tables[0].AliasName := 'REP';
Rep.Connect.Propagate := True;
Rep.ParamFields.ByName('Lang', '').CurrentValue := IIF(BiDiMode = bdRightToLeft, '2', '1');
Rep.ParamFields.ByName('SESSION_ID', '').CurrentValue := IntToStr(Session_id);
Rep.WindowState := wsMaximized;
Rep.Show;
The 1st parameter 'Lang' which created from crystal report pass well,
but the 2nd parameter 'SESSION_ID' which created from Oracle Stored Procedures give the following Error:
Error: 202 Parameter Name could not be found u2013 ParamFields.ByName
However in MS SQL Server the above code work fine with the 2 Parameters.
Any one has solution,Hello,
Click on the businessobjects Tab above and then select Samples and dowload the sample app you for your SDK. There are a few samples for changing/setting Parameters.
The Parameter collection has all parameters.
Thank you
Don -
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 -
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 -
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? -
. 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 data from Oracle stored procedures to Java
We're going to write a new web interface for a big system based on Oracle database. All business rules are already coded in PL/SQL stored procedures and we'd like to reuse as much code as possible. We'll write some new stored procedures that will combine the existing business rules and return the final result dataset.
We want to do this on the database level to avoid java-db round trips. The interface layer will be written in Java (we'd like to use GWT), so we need a way of passing data from Oracle stored procedures to Java service side. The data can be e.g. a set of properties of a specific item or a list of items fulfilling certain criteria. Would anyone recommend a preferable way of doing this?
We're considering one of the 2 following scenarios:
passing objects and lists of objects (DB object types defined on the schema level)
passing a sys_refcursor
We verified that both approaches are "doable", the question is more about design decision, best practice, possible maintenance problems, flexibility, etc.
I'd appreciate any hints.user1754151 wrote:
We're going to write a new web interface for a big system based on Oracle database. All business rules are already coded in PL/SQL stored procedures and we'd like to reuse as much code as possible. We'll write some new stored procedures that will combine the existing business rules and return the final result dataset.
We want to do this on the database level to avoid java-db round trips. The interface layer will be written in Java (we'd like to use GWT), so we need a way of passing data from Oracle stored procedures to Java service side. The data can be e.g. a set of properties of a specific item or a list of items fulfilling certain criteria. Would anyone recommend a preferable way of doing this?
We're considering one of the 2 following scenarios:
passing objects and lists of objects (DB object types defined on the schema level)
passing a sys_refcursor
We verified that both approaches are "doable", the question is more about design decision, best practice, possible maintenance problems, flexibility, etc.
I'd appreciate any hints.If logic is already written in DB, and the only concern is of passing the result to java service side, and also from point of maintenance problem and flexibility i would suggest to use the sys_refcursor.
The reason if Down the line any thing changes then you only need to change the arguments of sys_refcursor in DB and as well as java side, and it is much easier and less efforts compare to using and changes required for Types and Objects on DB and java side.
The design and best practise keeps changing based on our requirement and exisiting design. But by looking at your current senario and design, i personally suggest to go with sys_refcursor.
Maybe you are looking for
-
Page Size and Rotated printing Bug
When using the DataMax I4208 printer, I cannot use Crystal Reports 2008 as it will autorotate the text 90 degrees as it sees fit to the label. It is always wrong which causes the font size to be reduced to a super fine font too small for a microscop
-
Tax Calculations in Payroll process
Hi Experts, Can you please let me know how the Tax will calculate while payroll process? Based on what it will get calculate ? Thanks Murali
-
Curiosity: importData error
To import an XML I use the expression: xfa.host.importData(sFile); sFile is the name of the XML to import. It seems to work well, but on the warning ads tag of the program I always see an error that says that there is a command sequence error(Javascr
-
Plz help ASAP!!!!
Interactive objectives in Adobe Captivate 4 is not working in Flash Player ?
-
Why i cannot buy using my itune id?
Why i can use my itune id? Can i buy gems clash of clan using my itune card?