I want to send two arrays form java to oracle stored procedures. The first Array is array of strings and the second is array of chars how can I make this??
Look here: http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/oraarr.htm#i1058512
and here is my short example:
1) on database
SQL> create or replace type string_array as table of varchar2(100);
2 /
Type created.
SQL> create or replace function to_string(p_array in string_array) return varchar2
2 as
3 l_string varchar2(32767);
4 i binary_integer;
5 begin
6 i := p_array.first();
7 while i is not null loop
8 l_string := l_string || p_array(i) || ';';
9 i := p_array.next(i);
10 end loop;
11 l_string := rtrim(l_string, ';');
12 return l_string;
13 end;
14 /
Function created.
2) in java
public class ArrayTest {
public static void main(String[] args) throws SQLException {
DriverManager.registerDriver(new OracleDriver());
OracleConnection connection = (OracleConnection) DriverManager.getConnection(...);
String[] elements = {"abc", "def", "geh"};
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("STRING_ARRAY", connection);
ARRAY array = new ARRAY(descriptor, connection, elements);
OracleCallableStatement stmt = (OracleCallableStatement) connection.prepareCall("{? = call to_string(?)}");
stmt.registerOutParameter(1, Types.VARCHAR);
stmt.setARRAY(2, array);
stmt.execute();
String result = stmt.getString(1);
System.out.println("to_string returned: " + result);
}
}
seems to work: output says
to_string returned: abc;def;geh