Although I cannot speak from a .NET perspective, I have had similar issues with Java code. Perhaps this solution will be of some use...
Begin by creating a new TYPE
in the database capable of storing a collection of elements. I typically use a TABLE
type:
CREATE TYPE my_array_type IS TABLE OF NUMBER
INDEX BY BINARY_INTEGER;
You then create a procedure capable of accepting a parameter of type MY_ARRAY_TYPE
:
CREATE PROCEDURE process_array(my_array MY_ARRAY_TYPE) IS
i BINARY_INTEGER;
my_array_element NUMBER;
BEGIN
i := my_array.FIRST;
WHILE my_array.EXISTS(i) LOOP
my_array_element := my_array(i);
/* do something with my_array_element... */
i := my_array.NEXT(i);
END LOOP;
END;
The next trick is to dynamically build an anonymous PL/SQL block in your programming language of choice (I presume VB.NET or C#) and execute it. I can't speak much to .NET, but here is an example in Java:
int[] myArray = ...;
StringBuilder plsql = new StringBuilder();
plsql.append("DECLARE");
plsql.append(" my_array MY_ARRAY_TYPE;");
plsql.append("BEGIN");
for (int i = 0; i < myArray.length; i++) {
plsql.append(" my_array(" + i + ") := ?;");
}
plsql.append(" PROCESS_ARRAY(my_array);");
plsql.append("END");
CallableStatement statement = connection.prepareCall(plsql.toString());
for (int i = 0; i < myArray.length; i++) {
statement.setInt(i + 1, myArray[i]);
}
statement.execute();
I know there are better ways, but this seemed to be the most reliable, especially in the Java/JDBC world where only a subset of all of Oracle's JDBC drivers (!) support collection types.