我现有的c#代码要转换为批量插入。
我想使用数组绑定,但我的所有数据都保存在字符串列表中。转换此oracle存储过程调用以处理批量插入的最佳方法是什么?
这是代码
for (int i = 0; i < listSize.Count(); i++)
{
using (OracleCommand cmd = new OracleCommand())
{
OracleConnection conn;
conn = new OracleConnection(ConnectionStringOracle);
cmd.CommandText = "package.insertR";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.Add(new OracleParameter("oRetValue", OracleDbType.Varchar2, 10)).Direction = ParameterDirection.Output;
cmd.Parameters.Add(new OracleParameter("firstList", OracleDbType.Varchar2, 32767));
cmd.Parameters["firstList"].Value = rd.fl[i];
cmd.Parameters.Add(new OracleParameter("secondList", OracleDbType.Varchar2, 32767));
cmd.Parameters["secondList"].Value = rd.sl[i];
conn.Open();
try
{
cmd.ExecuteNonQuery();
}
conn.Close();
}
plsql中的示例插入是
PROCEDURE insertr(
oRetValue OUT varchar2,
firstListIN varchar2,
secondList IN varchar2,) AS
BEGIN
insert into tablename (first1,second1)
values (firstList,secondList);
END insertr;
答案 0 :(得分:0)
using (OracleCommand cmd = new OracleCommand())
{
OracleConnection conn;
conn = new OracleConnection(ConnectionStringOracle);
cmd.ArrayBindCount = listSize.Count();
cmd.CommandText = "package.insertR";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.Parameters.Add(new OracleParameter(":firstList", OracleDbType.Varchar2, 32767));
cmd.Parameters[":firstList"].Value = rd.fl.ToArray();
cmd.Parameters.Add(new OracleParameter(":secondList", OracleDbType.Varchar2, 32767));
cmd.Parameters[":secondList"].Value = rd.sl.ToArray();
conn.Open();
try
{
cmd.ExecuteNonQuery();
}
conn.Close();