How from ASP.NET I can call a stored procedure in an Oracle package that accepts a VArray. The VArray will pass a list of keys that the stored procedure will use to modify appropriate records. I know I could send the keys in separate calls or send a delimited list, but I'd rather use an array.
Asked
Active
Viewed 6,509 times
2 Answers
2
Assuming you're using ODP.NET (you shouldn't be using System.Data.OracleClient
anyway), here's how to do it:
using System;
using System.Data;
using Oracle.DataAccess.Client;
class SomeClass
{
void SomeMethod(string connectionString, int[] anArrayOfKeys)
{
using (var con = new OracleConnection(connectionString))
using (var cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "StoredProcedureNameGoesHere";
cmd.Parameters.Add(
"ParameterNameGoesHere",
OracleDbType.Array,
anArrayOfKeys,
ParameterDirection.Input);
con.Open();
cmd.ExecuteNonQuery();
}
}
}

Vadim K.
- 2,370
- 18
- 26
-1
OracleCommand cmd = OracleConnection1.CreateCommand();
cmd.CommandText = "INSERT INTO ArrayTable VALUES (:CODE, :TITLE, : ARR1, :ARR2)";
...
OracleArray arr1 = new OracleArray("SCOTT.TARRAY1", OracleConnection1);
arr1.Add(10);
arr1.Add(20);
arr1.Add(30);
...
cmd.Parameters["ARR1"].DbType = OracleDbType.Array;
cmd.Parameters["ARR1"].Value = arr1;
...
cmd.ExecuteNonQuery();

Craig
- 36,306
- 34
- 114
- 197
-
No I haven't tried it, nor would it meet my requirements as it inserts directly into the table rather than calling the stored procedure (which may do more than just a simple insert). It looks like you are referencing an Oracle array type (SCOTT.TARRAY1), so that does get me part way there. – Leigh Riffel Jan 14 '10 at 03:34
-
I didn't notice the link initially. This solution also requires purchasing dotConnect from devart. – Leigh Riffel Feb 19 '10 at 17:01