0

我有现有的 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;
4

1 回答 1

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();
于 2013-04-19T22:01:39.207 回答