Oracle:从c#批量更新记录

时间:2015-01-19 07:28:40

标签: c# oracle updates bulk

我有一个要求,我必须使用c#在Oracle中执行批量更新记录。我试图通过传递一个必须更新回oracle的记录ID数组来实现这一点,但代码无法正常工作。

我使用的最新代码是 -

List<Int64> listTransId = new List<Int64>();
while (reader.Read())
{
  listTransId.Add(Convert.ToInt64(reader["TOLL_TX_SEQ_NUM"]));
}

Int64[] arrTOLL_TX_SEQ_NUM = new Int64[listTransId.Count];
arrTOLL_TX_SEQ_NUM = listTransId.ToArray();

OracleTransaction txn =  connection.BeginTransaction(IsolationLevel.ReadCommitted);
OracleCommand updateCmd = new OracleCommand(@" BEGIN UPDATE TOLL_TRANSACTION SET CCH_EXPORT_DATETIME = SYSDATE WHERE TOLL_TX_SEQ_NUM = :TOLL_TX_SEQ_NUM; END;");
updateCmd.CommandType = CommandType.Text;
updateCmd.Connection = connection;
//update Cmd.BindByName = true;
update Cmd.ArrayBindCount = arrTOLL_TX_SEQ_NUM.Length;

OracleParameter TOLL_TX_SEQ_NUM = new OracleParameter("TOLL_TX_SEQ_NUM", OracleDbType.Int64);
TOLL_TX_SEQ_NUM.Direction = ParameterDirection.Input;
TOLL_TX_SEQ_NUM.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
TOLL_TX_SEQ_NUM.Value = arrTOLL_TX_SEQ_NUM;
TOLL_TX_SEQ_NUM.Size = arrTOLL_TX_SEQ_NUM.Length;

updateCmd.Parameters.Add(TOLL_TX_SEQ_NUM);
Console.WriteLine("Connection state - " + connection.State);
updateCmd.ExecuteNonQuery();
txn.Commit();

connection.Close();

1 个答案:

答案 0 :(得分:0)

使用“数组绑定”和简单的更新语句。

http://www.oracle.com/technetwork/issue-archive/2009/09-sep/o59odpnet-085168.html