跟一个第三方系统做接口,需要插入几百万条数据到Oracle数据库。
下载Oracle的Managed版本的ODP.NET组件,只需要一个Oracle.ManagedDataAccess.dll这个DLL就可以搞定了,使用数组参数的方式,可以毫秒级插入几百万条数据。
下载地址
http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html
示例代码如下:
string[] codeValue = new string[shopList.Count]; string[] nameValue = new string[shopList.Count]; int j = 0; foreach (Shop shop in shopList) { codeValue[j] = shop.Code; nameValue[j] = shop.CName; j++; } command = new OracleCommand(sql, connection); sql = string.Format("INSERT INTO SHOP_ALL VALUES(:Code,:CName)"); command.ArrayBindCount = shopList.Count; //批量插入记录的条数,一定要赋值 command.CommandText = sql; OracleParameter codePara = new OracleParameter("Code", OracleDbType.NVarchar2); codePara.Direction = ParameterDirection.Input; codePara.Value = codeValue; command.Parameters.Add(codePara); OracleParameter nameParameter = new OracleParameter("CName", OracleDbType.NVarchar2); nameParameter.Direction = ParameterDirection.Input; nameParameter.Value = nameValue; command.Parameters.Add(nameParameter); command.ExecuteNonQuery();