Oracle:从 c# 批量更新记录
Oracle: Bulk update of records from c#
我有一个要求,我必须使用 c# 在 Oracle 中执行批量记录更新。我试图通过将必须更新的记录 id 数组传递回 oracle 来实现这一点,但代码不起作用。
我使用的最新代码是-
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();
使用 "array binding" 和简单的更新语句。
http://www.oracle.com/technetwork/issue-archive/2009/09-sep/o59odpnet-085168.html
我有一个要求,我必须使用 c# 在 Oracle 中执行批量记录更新。我试图通过将必须更新的记录 id 数组传递回 oracle 来实现这一点,但代码不起作用。
我使用的最新代码是-
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();
使用 "array binding" 和简单的更新语句。
http://www.oracle.com/technetwork/issue-archive/2009/09-sep/o59odpnet-085168.html