Passing multidimensional array to plsql procedure
hi ,
is there any way to pass a two dimensional array of different data types to plsql procedure as a parameter?
In other words, is it possible to pass a set or records or a datatable as a single parameter to plsql procedure?
Because I am using a dataset selected with odp.net in my client and I am modifying the data in different datatables contained in the dataset.At the moment, the modified datatables are saved by seperating each column as a sepearate array and passing each column array as a seperate parameter to a stored procedure. But, I would like to change it in a way to pass each datatable as a single parameter to the stored procedure.
I would appreciate any solution/suggestion/hint in regard to this problem
thanks in advance,
Prabhakar.
If your Java array is of a base type (String, int, etc.) and you are using the OCI driver, you can use OracleCallableStatement.setPlSqlTable(). (I'm doing this from memory so the method name may be slightly different.)
The method takes a Java array and converts it to a PL/SQL table before passing it to the stored procedure.
Similar Messages
-
How to pass an array in Oracle Procedure
If I have to pass an array as an argument in Oracle Procedure/function. How to do that ??
For example, I have to pass the names of employess and then for these employess I have to do something in Oracle Procedure.
Thanks & Regards,
VinayHi!
Here is an example:
create or replace procedure test
is
type v2_itt is table of varchar2(2000) index by binary_integer;
l_v2 v2_itt;
procedure test2( pi_v2 v2_itt ) is
begin
for i in 1 .. pi_v2.count loop
dbms_output.put_line( pi_v2(i) );
end loop;
end;
begin
l_v2(1) := 'name1';
l_v2(2) := 'name2';
test2( l_v2 );
end;
Regards,
Andrew Velitchko
BrainBench MVP for Developer/2000
http://www.brainbench.com -
How to pass an array to a procedure & how to use array in IN clause in SQL
Hi all,
how do i pass an array of varchar2[10] in an procedure and i want to use this array in the IN caluse of the SQL statement inside the procedure. Can anyone please help me on this.
Thanks & regards
shyam~There are multiple ways. For example:
SQL> create or replace
2 type str10_tbl_type is table of varchar2(10)
3 /
Type created.
SQL> -- Using TABLE operator
SQL> create or replace
2 procedure p1(
3 p_str10_tbl str10_tbl_type
4 )
5 is
6 begin
7 for rec in (
8 select ename,
9 sal
10 from emp,
11 table(p_str10_tbl)
12 where ename = column_value
13 ) loop
14 dbms_output.put_line(rpad(rec.ename,10) || rec.sal);
15 end loop;
16 end;
17 /
Procedure created.
SQL> set serveroutput on format wrapped
SQL> exec p1(str10_tbl_type('KING','ALLEN','SMITH'));
KING 5000
ALLEN 1600
SMITH 800
PL/SQL procedure successfully completed.
SQL> -- Using MEMBER OF method
SQL> create or replace
2 procedure p1(
3 p_str10_tbl str10_tbl_type
4 )
5 is
6 begin
7 for rec in (
8 select ename,
9 sal
10 from emp
11 where ename member of p_str10_tbl
12 ) loop
13 dbms_output.put_line(rpad(rec.ename,10) || rec.sal);
14 end loop;
15 end;
16 /
Procedure created.
SQL> set serveroutput on format wrapped
SQL> exec p1(str10_tbl_type('KING','ALLEN','SMITH'));
SMITH 800
ALLEN 1600
KING 5000
PL/SQL procedure successfully completed.
SQL> SY. -
I want to pass String array to Stored procedure .
ArrayDescriptor claim = ArrayDescriptor.createDescriptor("POOJA.VARCHAR_TBL" , conn);
String test[] = {"an","jk"};
ARRAY a = new ARRAY(claim,conn,test);
cstmt.setArray(noOfParms,a);
It gives class cast exception at ArrayDescriptor .. Dont know why ?
Need an urgent help ...ArrayBinding feature is for bulk operation where a SP or SQL statement executes ArrayBindCount time in one server round trip. Each execution uses the nth element in the parameter (array) and execute the SP or SQL statement.
This is done internally in the database, and not related to the SP or SQL statement at all.
The PL/SQL Associative array support might be the feature that you're looking for.
Please take a look from our Doc on these topics for further information. Also take a look in the ODP.NET dissucssion forum's samples section.
Thanks
Martha -
Passing an array as parameter from java (java controls) to stored procedure
Hi,
I'm using java controls (BEA Weblogic Workshop 8.1) to call a stored procedure and send an array as a parameter to the stored procedure from java. The following code below throws an exception "Fail to convert to internal representation".
Java code
import com.bea.control.DatabaseControl.SQLParameter;
// Here i create the java array
int[] javaArray={12,13,14};
//The code below is used to create the oracle sql array for the procedure
SQLParameter[] params = new SQLParameter[1];
Object obj0=javaArray;
params[0] = new SQLParameter(obj0, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
// the code below calls the testFunc method in OJDBCtrl.jcx file
String succ= dbControl.testFunc(params);
OJDBCtrl.jcx
* @jc:sql statement="call CMNT_TST_PROC(?))"
String testFunc(SQLParameter[] param);
The stored procedure used:
TYPE SL_tab IS TABLE OF number INDEX BY PLS_INTEGER;
Procedure cmnt_tst_proc (cmnt_tst sl_tab);
Procedure cmnt_tst_proc (cmnt_tst sl_tab) is
BEGIN
dbms_output.put_line('Hello');
END;
I am getting the following exception
Failure=java.sql.SQLException: Fail to convert to internal representation: [I@438af4 [ServiceException]>
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
at oracle.jdbc.driver.DatabaseError.check_error(DatabaseError.java:861)
at oracle.sql.ARRAY.toARRAY(ARRAY.java:210)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7768)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7449)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7837)
at oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4587)
at weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:244)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl._setParameter(DatabaseControlImpl.jcs:1886)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1732)
at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2591)
at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:377)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:433)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:406)
at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:249)
at com.bea.wlw.runtime.jcs.container.JcsContainer.invoke(JcsContainer.java:85)
at com.bea.wlw.runtime.core.bean.BaseContainerBean.invokeBase(BaseContainerBean.java:224)
at com.bea.wlw.runtime.core.bean.SLSBContainerBean.invoke(SLSBContainerBean.java:109)
at com.bea.wlwgen.StatelessContainer_ly05hg_ELOImpl.invoke(StatelessContainer_ly05hg_ELOImpl.java:153)
Can you please let me know, what i'm doing wrong and how i can pass an array to a procedure/function using java controls.
Any help will be highly appreciated.
Edited by: user12671762 on Feb 24, 2010 5:03 AM
Edited by: user9211663 on Feb 24, 2010 9:04 PMThanks Michael.
Here's the final code that i used, this might be helpful for those who face this problem
Java Code
// Following code gets the connection object
InitialContext ctx = new InitialContext();
dataSource = (DataSource)ctx.lookup("<DataSourceName>");
conn=dataSource.getConnection();
// Following code is used to create the array type from java
String query="CREATE OR REPLACE TYPE STR_ARRAY AS VARRAY(3) OF NUMBER";
dbControl.runTypeQuery(query);
// Following code is used to obtain the oracle sql array as SQLParameter
ArrayDescriptor desc = ArrayDescriptor.createDescriptor("<schemaName>.STR_ARRAY", conn);
Object[] elements = new Object[3];
elements[0] = new Integer(12);
elements[1] = new Integer(13);
elements[2] = new Integer(14);
oracle.sql.ARRAY newArray = new oracle.sql.ARRAY( desc, conn, elements);
SQLParameter[] params = new SQLParameter[1];
params[0] = new SQLParameter(newArray, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
String succ= dbControl.testFunc(params); -
Passing array to the procedure in parameter
Hi
I tried the following code,
Where my aim is to split the comma separated values and insert into an array, and then pass that array to another procedure in a package
CREATE OR REPLACE PACKAGE PAK_SPLIT_TEST AS
PROCEDURE PROC_SPLIT(IN_LIST VARCHAR2) ;
END;
CREATE OR REPLACE PACKAGE PAK_SPLIT_TEST AS
PROCEDURE PROC_SPLIT(IN_LIST VARCHAR2) ;
END;
CREATE OR REPLACE PACKAGE PAK_SPLIT_TEST
AS
PROCEDURE PROC_SPLIT (IN_LIST VARCHAR2);
END;
CREATE OR REPLACE PACKAGE BODY PAK_SPLIT_TEST
AS
PROCEDURE PROC_REM_LIST (p_array l_data)
IS
BEGIN
FOR i IN 1 .. p_array.COUNT
LOOP
DBMS_OUTPUT.put_line (p_array (i));
END LOOP;
END;
PROCEDURE PROC_SPLIT (IN_LIST VARCHAR2)
IS
TYPE SPLIT_array IS TABLE OF VARCHAR2 (4000)
INDEX BY BINARY_INTEGER;
l_data SPLIT_array;
l_txt LONG := '100,200,300,400,500,600';
l_str LONG := IN_LIST || ',';
l_n NUMBER;
BEGIN
BEGIN
l_data.delete;
LOOP
l_n := INSTR (l_str, ',');
EXIT WHEN NVL (l_n, 0) = 0;
l_data (l_data.COUNT + 1) := SUBSTR (l_str, 1, l_n - 1);
l_str := SUBSTR (l_str, l_n + 1);
END LOOP;
PROC_REM_LIST (l_data);
END;
END;
SELECT *FROM USER_ERRORSI'm getting the following error at line no. 30
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin end function package pragma procedure formCould you please help me in this
Thanks,
SmileGive this a shot:
CREATE OR REPLACE PACKAGE BODY PAK_SPLIT_TEST
AS
TYPE SPLIT_array IS TABLE OF VARCHAR2 (4000)
INDEX BY BINARY_INTEGER;
PROCEDURE PROC_REM_LIST (p_array SPLIT_array)
IS
BEGIN
FOR i IN 1 .. p_array.COUNT
LOOP
DBMS_OUTPUT.put_line (p_array (i));
END LOOP;
END;
PROCEDURE PROC_SPLIT (IN_LIST VARCHAR2)
IS
l_data SPLIT_array;
l_txt LONG := '100,200,300,400,500,600';
l_str LONG := IN_LIST || ',';
l_n NUMBER;
BEGIN
BEGIN
l_data.delete;
LOOP
l_n := INSTR (l_str, ',');
EXIT WHEN NVL (l_n, 0) = 0;
l_data (l_data.COUNT + 1) := SUBSTR (l_str, 1, l_n - 1);
l_str := SUBSTR (l_str, l_n + 1);
END LOOP;
PROC_REM_LIST (l_data);
END;
END;
END pak_split_test;
/PROC_REM_LIST was expecting a PL/SQL type of L_DATA. You have not defined that type anywhere (e.g. in your package spec, body, or in SQL). I move the declaration from PROC_SPLIT to your package body and it compiles.
Hope this helps! -
Hi
i want to pass an array to a procedure and get the employee details from emp table..
for that i tried the following way
CREATE OR REPLACE package pak as
type tp is table of emp.emp_type%type;
procedure procc (cur out sys_refcursor,emptype in tp);
end;
CREATE OR REPLACE package body pak as
procedure procc (cur out sys_refcursor ,emptype in tp)
is
begin
open cur for
select * from emp where emp_type in(emptype);
end;
end;
but am getting the following error while compilation
PLS-00642: local collection types not allowed in SQL statements..
here emptype is an array..and i want to get all the detail of employee of the selected types..
please help me with this
regards
benwhy it is not supporting table.column%typeBecause COLUMN%TYPE is a piece of PL/SQL syntax not SQL syntax. So we cannot define a SQL type using COLUMN%TYPE. Unfortunately, in order to be able to use a Type in a SELECT * FROM TABLE() function it has to be a SQL type.
As for why SQL Types have this limitation, it is - like many other limitations of the CDT implementation - a product of the ability to use CDTs as column definitions. Consider the following scenario....
CREATE TABLE my_tab (col1 varchar2(18))
CREATE TYPE my_new_type AS OBJECT (attr1 my_tab.col1%TYPE);
CREATE TABLE my_obj_tab (col_a my_new_type)
INSERT INTO my_obj_tab VALUES ('This is not a date')
ALTER TABLE my_tab MODIFY col1 DATE
/Does Oracle have to validate every single usage of my_new_type to ensure that all its values are capable of date conversion? Of course not. It won't let us modify any column that contains data.
It's unfortunate that this has a knock-on effect on those of us who just want to use Types as programming constructs and not for storage but them's the breaks.
Cheers, APC -
How to pass int array as an IN parameter to PLSQL Procedure
Hi,
How to pass int array in java to a stored procedure througn jdbc
and what type of data type I should declare to this IN parameter
in PLSQL Procedure.
Thanks,
SimiHi,
The best way to do what you want depends on what you want. Start by describing what you need to do. It's best to post some sample data (CREATE TABLE and INSERT statments) and what results you want from that sample data. (See the forum FAQ: https://forums.oracle.com/message/9362002)
If you have ideas about how to do the job (e.g., populating a temporary table) it can be helpful to include those, too, but distinguish clearly between WHAT you need to do and HOW you might do it.
As Bencol suggested, a SYS_REFCURSOR might be the best way to pass back the results.
Since you didn't post your table, or even describe what you wanted to do with it, I'll illustrate using scott.emp, which is probably on your system.
Say you wanted a procedure that took a DATE as an argument, and returned a some designated columns (empno, ename and hiredate in the example below) for all employees hired on or after the given DATE. You might write a procedure like this:
CREATE OR REPLACE PROCEDURE hired_since
( start_date IN DATE
, out_data OUT SYS_REFCURSOR
AS
BEGIN
OPEN out_data FOR
SELECT empno, ename, hiredate
FROM scott.emp
WHERE hiredate >= start_date;
END hired_since;
SHOW ERRORS
You can test it in SQL*Plus like this:
VARIABLE c REFCURSOR
EXEC hired_since (DATE '1982-01-01', :c);
PRINT :c
The output I got from this test was:
EMPNO ENAME HIREDATE
7788 SCOTT 19-APR-87
7876 ADAMS 23-MAY-87
7934 MILLER 23-JAN-82 -
How to pass a multidimensional array to an Oracle procedure?
How can I pass a multidimensional array to oracle array?
Thanx in anticipation,Look in to passing user defined type back and forth to Oracle. Any type that oracle supports, you can constract on the java side and send it across. Look into the SQLData class.
-
Passing an array in a for loop to a procedure
I am trying to pass an array in a cursor for loop to a procedure which performs a table insert using the array's contents. Somehow I am missing something, or it is not possible. The compile error states: PLS-00306: wrong number or types in call to 'insert_address' I checked to be sure I am creating the arrays in both cases from similar data objects. Both address and work_address_table contain the same 4 columns with the same data types.
create or replace package work_address as
FUNCTION populate_address return boolean;
procedure insert_address(in_address IN work_address_table%ROWTYPE);
end work_address;
create or replace package body work_address as
function populate_address return boolean is
cursor c1 is
select 'H' as header,
street1 as street
city as city,
NULL as state
from address
where city = 'HANOVER';
TYPE addressT IS TABLE OF c1%ROWTYPE INDEX BY BINARY_INTEGER;
rec1 addressT;
BEGIN
OPEN c1;
FETCH c1 BULK COLLECT INTO rec1 LIMIT 500;
FOR i IN 1..rec1.count LOOP
rec1(i).state := 'US'
insert_address(rec1(i));
exit when c1%notfound;
END LOOP;
CLOSE c1;
return TRUE;
END populate_address;
PROCEDURE insert_address(in_address IN work_address_table%ROWTYPE) IS
BEGIN
INSERT INTO work_address_table
VALUES (in_address.header,
in_address.street,
in_address.city,
in_address.state);
COMMIT;
END insert_address;
END work address;
/Both address and work_address_table contain the same 4 columns with the same data types.Are you 100% sure about this?
SQL> declare
cursor c1
is
select 1 deptno, dummy dname, 'Loc' location from dual;
type addresst is table of c1%rowtype
index by binary_integer;
rec1 addresst;
procedure p (d dept%rowtype)
as
begin
dbms_output.put_line(d.dname);
end p;
begin
rec1 (1).dname := 'z';
p (rec1 (1));
end;
z
PL/SQL procedure successfully completed.but changing just the first column of the cursor:
SQL> declare
cursor c1
is
select 'xy' deptno, dummy dname, 'Loc' location from dual;
type addresst is table of c1%rowtype
index by binary_integer;
rec1 addresst;
procedure p (d dept%rowtype)
as
begin
dbms_output.put_line(d.dname);
end p;
begin
rec1 (1).dname := 'z';
p (rec1 (1));
end;
Error at line 3
ORA-06550: line 20, column 3:
PLS-00306: wrong number or types of arguments in call to 'P'
ORA-06550: line 20, column 3:
PL/SQL: Statement ignored -
Trying to pass array to stored procedure in a loop using bind variable
All,
I'm having trouble figuring out if I can do the following:
I have a stored procedure as follows:
create procedure enque_f826_utility_q (inpayload IN f826_utility_payload, msgid out RAW) is
enqopt dbms_aq.enqueue_options_t;
mprop dbms_aq.message_properties_t;
begin
dbms_aq.enqueue(queue_name=>'f826_utility_queue',
enqueue_options=>enqopt,
message_properties=>mprop,
payload=>inpayload,
msgid=>msgid);
end;
The above compiles cleanly.
The first parameter "inpayload" a database type something like the following:
create or replace type f826_utility_payload as object
2 (
3 YEAR NUMBER(4,0),
4 MONTH NUMBER(2,0),
83 MUSTHAVE CHAR(1)
84 );
I'd like to call the stored procedure enque_f826_utility_q in a loop passing to it
each time, new values in the inpayload parameter.
My questions are:
First, I'm not sure in php, how to construct the first parameter which is a database type.
Can I just make an associative array variable with the keys of the array the same as the columns of the database type shown above and then pass that array to the stored procedure?
Second, is it possible to parse a statement that calls the enque_f826_utility_q procedure using bind variables and then execute the call to the stored procedure in a loop passing new bind variables each time?
I've tried something like the following but it's not working:
$conn = oci_pconnect (....);
$stmt = "select * from f826_utility";
$stid = oci_parse($conn, $sqlstmt);
$r = oci_execute($stid, OCI_DEFAULT);
$row = array();
$msgid = "";
$enqstmt = "call enque_f826_utility_q(:RID,:MID)";
$enqstid = oci_parse($conn, $sqlstmt);
oci_bind_by_name($enqstid, ":RID", $row); /* line 57 */
oci_bind_by_name($enqstid, ":MID", $msgid);
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC))
++$rowcnt;
if (! oci_execute($enqstid)) /* line 65 */
echo "Error";
exit;
When I run this, I get the following:
PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
ine 57
Entering loop to process records from F826_UTIITY table
PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
ine 65
PHP Warning: oci_execute(): ORA-06553: PLS-306: wrong number or types of argume
nts in call to 'ENQUE_F826_UTILITY_Q' in C:\Temp\enqueue_f826_utility.php on lin
e 65
PHP Notice: Undefined variable: msgnum in C:\Temp\enqueue_f826_utility.php on l
ine 68
Error during oci_execute of statement select * from F826_UTILITY
Exiting!Thanks for the reply.
I took a look at this article. What it appears to describe is
a calling a stored procedure that takes a collection type which is an array.
Does anyone from Oracle know if I can pass other database type definitions to a stored procedure from PHP?
I have a type defined in my database similar to the following which is not
an array but a record of various fields. This type corresponds to a payload
of an advanced queue payload type. I have a stored procedure which will take as it's input, a payload type of this structure and then enqueue it to a queue.
So I want to be able to pass a database type similar to the following type definition from within PHP. Can anyone from Oracle verify whether or not this is possible?
create or replace type f826_utility_payload as object
YEAR NUMBER(4,0),
MONTH NUMBER(2,0),
UTILITY_ID NUMBER(10,0),
SUBMIT_FAIL_BY VARCHAR2(30),
MUSTHAVE CHAR(1)
); -
How to pass value in array to another procedure?
Hello.
I have created application by Developer form9i.
And I have some problem about passing value in array to another procedure.
My code is :
PROCEDURE p_add_array (col_no in number,
col_val in varchar2) IS
type xrecord is record(col number,vcol varchar2(1000));
xrec xrecord;
type varraytype is varying array(42) of xrecord;
xvartab varraytype := varraytype();
alert number;
BEGIN
set_application_property(cursor_style,'busy');
xrec.col := col_no;
xrec.vcol := col_val;
xvartab.extend(1);
xvartab(col) := xrec;
EXCEPTION
when others then
set_application_property(cursor_style,'default');
alert := f_show_alert('!Error ORA-'||
to_char(DBMS_ERROR_CODE)||' '||
substr(DBMS_ERROR_TEXT,1,240),
'al_stop');
END;
And I want to have
PROCEDURE p_print_arrey is
BEGIN
END;
So how to bring value of xvartab( ) in p_add_array to use in p_print_array?
Anybody please help me solve this ploblem.Hi,
Instead of declaring the array locally within the procedure (i.e. p_add_array), define it in the package specification (i.e. Under Program Units).
-- Shailender Mehta -- -
Pass an array of a user defined class to a stored procedure in java
Hi All,
I am trying to pass an array of a user defined class as an input parameter to a stored procedure. So far i have done the following:
Step 1: created an object type.
CREATE TYPE department_type AS OBJECT (
DNO NUMBER (10),
NAME VARCHAR2 (50),
LOCATION VARCHAR2 (50)
Step 2: created a varray of the above type.
CREATE TYPE dept_array1 AS TABLE OF department_type;
Step 3:Created a package to insert the records.
CREATE OR REPLACE PACKAGE objecttype
AS
PROCEDURE insert_object (d dept_array);
END objecttype;
CREATE OR REPLACE PACKAGE BODY objecttype
AS
PROCEDURE insert_object (d dept_array)
AS
BEGIN
FOR i IN d.FIRST .. d.LAST
LOOP
INSERT INTO department
VALUES (d (i).dno,d (i).name,d (i).location);
END LOOP;
END insert_object;
END objecttype;
Step 4:Created a java class to map the columns of the object type.
public class Department
private double DNO;
private String Name;
private String Loation;
public void setDNO(double DNO)
this.DNO = DNO;
public double getDNO()
return DNO;
public void setName(String Name)
this.Name = Name;
public String getName()
return Name;
public void setLoation(String Loation)
this.Loation = Loation;
public String getLoation()
return Loation;
Step 5: created a method to call the stored procedure.
public static void main(String arg[]){
try{
Department d1 = new Department();
d1.setDNO(1); d1.setName("Accounts"); d1.setLoation("LHR");
Department d2 = new Department();
d2.setDNO(2); d2.setName("HR"); d2.setLoation("ISB");
Department[] deptArray = {d1,d2};
OracleCallableStatement callStatement = null;
DBConnection dbConnection= DBConnection.getInstance();
Connection cn = dbConnection.getDBConnection(false); //using a framework to get connections
ArrayDescriptor arrayDept = ArrayDescriptor.createDescriptor("DEPT_ARRAY", cn);
ARRAY deptArrayObject = new ARRAY(arrayDept, cn, deptArray); //I get an SQLException here
callStatement = (OracleCallableStatement)cn.prepareCall("{call objecttype.insert_object(?)}");
((OracleCallableStatement)callStatement).setArray(1, deptArrayObject);
callStatement.executeUpdate();
cn.commit();
catch(Exception e){
System.out.println(e.toString());
I get the following exception:
java.sql.SQLException: Fail to convert to internal representation
My question is can I pass an array to a stored procedure like this and if so please help me reslove the exception.
Thank you in advance.OK I am back again and seems like talking to myself. Anyways i had a talk with one of the java developers in my team and he said that making an array of structs is not much use to them as they already have a java bean/VO class defined and they want to send an array of its objects to the database not structs so I made the following changes to their java class. (Again hoping some one will find this useful).
Setp1: I implemented the SQLData interface on the department VO class.
import java.sql.SQLData;
import java.sql.SQLOutput;
import java.sql.SQLInput;
import java.sql.SQLException;
public class Department implements SQLData
private double DNO;
private String Name;
private String Location;
public void setDNO(double DNO)
this.DNO = DNO;
public double getDNO()
return DNO;
public void setName(String Name)
this.Name = Name;
public String getName()
return Name;
public void setLocation(String Location)
this.Location = Location;
public String getLoation()
return Location;
public void readSQL(SQLInput stream, String typeName)throws SQLException
public void writeSQL(SQLOutput stream)throws SQLException
stream.writeDouble(this.DNO);
stream.writeString(this.Name);
stream.writeString(this.Location);
public String getSQLTypeName() throws SQLException
return "DOCCOMPLY.DEPARTMENT_TYPE";
Step 2: I made the following changes to the main method.
public static void main(String arg[]){
try{
Department d1 = new Department();
d1.setDNO(1);
d1.setName("CPM");
d1.setLocation("LHR");
Department d2 = new Department();
d2.setDNO(2);
d2.setName("Admin");
d2.setLocation("ISB");
Department[] deptArray = {d1,d2};
OracleCallableStatement callStatement = null;
DBConnection dbConnection= DBConnection.getInstance();
Connection cn = dbConnection.getDBConnection(false);
ArrayDescriptor arrayDept = ArrayDescriptor.createDescriptor("DEPT_ARRAY", cn);
ARRAY deptArrayObject = new ARRAY(arrayDept, cn, deptArray);
callStatement = (OracleCallableStatement)cn.prepareCall("{call objecttype.insert_array_object(?)}");
((OracleCallableStatement)callStatement).setArray(1, deptArrayObject);
callStatement.executeUpdate();
cn.commit();
catch(Exception e){
System.out.println(e.toString());
and it started working no more SQLException. (The changes to the department class were done manfully but they tell me JPublisher would have been better).
Regards,
Shiraz -
Can I pass an array as an input parameter for a stored procedure on SQL Server 2000
I am trying to pass an array to a stored procedure residing on my SQL Server 2000 database server. Is this even possible? If it is possible, what is the syntax for this?
Any help would be greatly appreciated.
ThanksI have passed arrays to and from a database using SQL and ActiveX, including to and from stored procedures, but I cannot recall the precise method used to do so. If memory serves, everything is in the form of a string. You need to do a lot of parsing and 'unparsing' to get this data into your stored procedure.
You are left with a couple of options to get your data to the stored procedure. I recommend using SQL in LabVIEW wherever possible as it saves the amount of external code calls (and believe me, calling ActiveX procedures developed by someone else in Visual Basic is NOT much fun at all...). You can either send the array and other data to the stored procedure (you will find the syntax in the SQL references in LabVIEW help under SQL), or you can send
the array to the database, and have the database then act upon the array.
I strongly recommend making routines (subVIs) to handle these operations.
Sorry I don't have the syntax, I don't have SQL installed on this machine. If you can't find the syntax in the help, please post here again.
-Mike Du'Lyea -
How to pass ARRAY to Oracle Procedure
Hi
We are using BC4J with JSP in our project. We need to send an Array to the procedure.
Could somebody provide some info as how this can be achieved.A while back, I used a SQLJ client to call a Java (also SQLJ) stored procedure and I needed to pass an array of strings to the procedure. I did something like this:
Java Class that was loaded in DB:
public class MyClass
// method that the stored procedure uses
public static void CALL_DOSTUFF(String a,
oracle.sql.ARRAY b,
oracle.sql.ARRAY c)
String[] bb = (String[])b.getArray();
String[] cc = (String[])c.getArray();
doStuff(a,bb,cc);
public static void doStuff(String a,
String[] b,
String[] c)
// process the input
In the database I added the type:
create or replace type STR_ARRAY as table of varchar2(20);
and the procedure:
create or replace procedure CALL_DOSTUFF(a varchar2,
b STR_ARRAY,
c STR_ARRAY)
as
language java
name 'MyClass.CALL_DOSTUFF(java.lang.String,
oracle.sql.ARRAY,
oracle.sql.ARRAY)';
I then used jpub to publish a STR_ARRAY.java file. I compiled this and used it with my SQLJ client to call to the stored procedure. The STR_ARRAY constructor takes a String[], so you do something like this in the SQLJ client:
String x = "X";
String y = {"y1","y2"};
String z = {"z1","z2"};
STR_ARRAY y1 = new STR_ARRAY(y);
STR_ARRAY z1 = new STR_ARRAY(z);
#sql {CALL CALL_DOSTUFF(:x,:y1,:z1)};
Hope this helps.
Maybe you are looking for
-
How to deal with deadlock on wwv_flow_data table when http server times out
There are some threads about a deadlock on the wwv_flow_data table. None of them contain a real explanation for this behaviour. In my case I will try to explain what I think is happening. Maybe it helps somebody who is hitting the same matter. In my
-
I am working with SharePoint 2010 Foundation. When I add a web part (a library, list, calendar, etc.) to the main page of my site, the body of the web part is fine. However, there's a problem with the drop down arrow on the far right side of the Ti
-
Hi, Not sure if anyone has noticed this, but we ran in to this issue last week on our sandbox environment and really bugged us. We logged in to the console, and we triggered some events to be kicked off. But nothing was happening, and all the routing
-
Promoted Links Launch Behavior: Dialog
When using the Promoted Links app, and using the Dialog launch behavior, every link I have tried returns an error. This does not happen with the other two launch behaviors, 'In page navigation and New tab'. I have tried opening several links that I k
-
MS IE Script Error in Skin Editor
When I try to edit a skin, the Skin edit window opens and the follow error message displays: Internet Explorer Script Error !!! An error has occured in the script on this page. Line: 222 Char: 3 Error: An automation server can't create object Code: 0