当前位置:   article > 正文

c# mysql、sqlserver、Oracle、pg批量插入_sql批量插入

sql批量插入

1、c#对多种数据库批量插入封装,方便调用;

MySql社区驱动MySqlConnector提供的批量插入方式是SqlBulkCopy,基于MySql自身的文件上传机制进行批量插入,参数为一个dataTable对象,原生的批量插入代码如下,计时方式与SqlServer相同,同时,MySql的连接字符串里要添加";AllowLoadLocalInfile=true",即连接字符串的形式应该是"Server= ;Database=;User ID=;Password=;AllowLoadLocalInfile=true",同时在MySql数据库上执行"set global local_infile=1"开启批量上传

  1. /// <summary>
  2. /// MySqlBulkInsert
  3. /// </summary>
  4. /// <typeparam name="T">插入的表对应的model</typeparam>
  5. /// <param name="list">插入的数据</param>
  6. /// <param name="tableName">泛型中无法获取到表,直接传表名称</param>
  7. /// <returns></returns>
  8. private bool MySqlBulkInsert<T>(IEnumerable<T> list, string tableName = "") where T : class
  9. {
  10. var connectionString = MSEApplication.GetConfigValue("ConnectionStrings:BulkConn");
  11. using (var conn = new MySqlConnection(connectionString))
  12. {
  13. try
  14. {
  15. var tableEntity = DataCommonUtil.GetTableEntity<T>();
  16. if (!string.IsNullOrWhiteSpace(tableName))
  17. tableEntity.TableName = tableName;
  18. MySqlBulkCopy sqlBulkCopy = new MySqlBulkCopy(conn, null);
  19. sqlBulkCopy.DestinationTableName = tableEntity.TableName;
  20. var dataTable = list.ToDataTable();
  21. int i = 0;
  22. foreach (DataColumn dataColumn in dataTable.Columns)
  23. {
  24. sqlBulkCopy.ColumnMappings.Add(new MySqlBulkCopyColumnMapping(i, dataColumn.ColumnName));
  25. i = i + 1;
  26. }
  27. conn.Open();
  28. var bulkCopyResult = sqlBulkCopy.WriteToServer(dataTable);
  29. if (bulkCopyResult.RowsInserted == list.Count())
  30. return true;
  31. else
  32. return false;
  33. }
  34. catch (Exception ex)
  35. {
  36. conn.Close();
  37. conn.Dispose();
  38. return false;
  39. }
  40. finally
  41. {
  42. conn.Close();
  43. conn.Dispose();
  44. }
  45. }
  46. }

SqlServer官方提供的批量插入方式是SqlBulkCopy。

  1. /// <summary>
  2. /// SqlServerBulkInsert
  3. /// </summary>
  4. /// <typeparam name="T">插入的表对应的model</typeparam>
  5. /// <param name="list">插入的数据</param>
  6. /// <param name="tableName">泛型中无法获取到表,直接传表名称</param>
  7. /// <returns></returns>
  8. private bool SqlServerBulkInsert<T>(IEnumerable<T> list, string tableName = "") where T : class
  9. {
  10. var connectionString = MSEApplication.GetConfigValue("ConnectionStrings:BulkConn");
  11. using (var conn = new SqlConnection(connectionString))
  12. {
  13. try
  14. {
  15. var tableEntity = DataCommonUtil.GetTableEntity<T>();
  16. if (!string.IsNullOrWhiteSpace(tableName))
  17. tableEntity.TableName = tableName;
  18. SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(conn, SqlBulkCopyOptions.KeepIdentity, null);
  19. sqlBulkCopy.DestinationTableName = tableEntity.TableName;
  20. sqlBulkCopy.BatchSize = 20000;
  21. var dataTable = list.ToDataTable();
  22. foreach (DataColumn dataColumn in dataTable.Columns)
  23. {
  24. sqlBulkCopy.ColumnMappings.Add(dataColumn.ColumnName, dataColumn.ColumnName);
  25. }
  26. conn.Open();
  27. sqlBulkCopy.WriteToServer(dataTable);
  28. return true;
  29. }
  30. catch (Exception ex)
  31. {
  32. conn.Close();
  33. conn.Dispose();
  34. return false;
  35. }
  36. finally
  37. {
  38. conn.Close();
  39. conn.Dispose();
  40. }
  41. }
  42. }
  1. /// <summary>
  2. /// OracleBulkInsert
  3. /// </summary>
  4. /// <typeparam name="T"></typeparam>
  5. /// <param name="list"></param>
  6. /// <param name="tableName">泛型中无法获取到表,直接传表名称</param>
  7. /// <returns></returns>
  8. private bool OracleBulkInsert<T>(IEnumerable<T> list, string tableName = "") where T : class
  9. {
  10. var connectionString = MSEApplication.GetConfigValue("ConnectionStrings:BulkConn");
  11. using (var conn = new OracleConnection(connectionString))
  12. {
  13. using (var adapter = new OracleDataAdapter())
  14. {
  15. var tableEntity = DataCommonUtil.GetTableEntity<T>();
  16. if (!string.IsNullOrWhiteSpace(tableName))
  17. tableEntity.TableName = tableName;
  18. var dataTable = list.ToDataTable();
  19. adapter.InsertCommand = new OracleCommand();
  20. adapter.InsertCommand.CommandText = $"INSERT INTO {tableEntity.TableName} ({string.Join(",", dataTable.Columns.Cast<DataColumn>().Select(c => c.ColumnName))})" +
  21. $" VALUES ({string.Join(",", dataTable.Columns.Cast<DataColumn>().Select(c => ":" + c.ColumnName))})";
  22. adapter.InsertCommand.Connection = conn;
  23. foreach (DataColumn column in dataTable.Columns)
  24. {
  25. adapter.InsertCommand.Parameters.Add($":{column.ColumnName}", column.DataType.ConvertToOracleDbType(), column.MaxLength, column.ColumnName);
  26. }
  27. adapter.UpdateBatchSize = 20000;
  28. conn.Open();
  29. using (var transaction = conn.BeginTransaction())
  30. {
  31. try
  32. {
  33. adapter.InsertCommand.Transaction = transaction;
  34. adapter.Update(dataTable);
  35. transaction.Commit();
  36. return true;
  37. }
  38. catch (Exception ex)
  39. {
  40. transaction.Rollback();
  41. conn.Close();
  42. conn.Dispose();
  43. return false;
  44. }
  45. finally
  46. {
  47. conn.Close();
  48. conn.Dispose();
  49. }
  50. }
  51. }
  52. }
  53. }

  1. /// <summary>
  2. /// PostgresqlBulkInsert
  3. /// </summary>
  4. /// <typeparam name="T">插入的表对应的model</typeparam>
  5. /// <param name="list">插入的数据</param>
  6. /// <param name="tableName">泛型中无法获取到表,直接传表名称</param>
  7. /// <returns></returns>
  8. private bool PostgresqlBulkInsert<T>(IEnumerable<T> list, string tableName = "") where T : class
  9. {
  10. var connectionString = MSEApplication.GetConfigValue("ConnectionStrings:BulkConn");
  11. using (var conn = new NpgsqlConnection(connectionString))
  12. {
  13. conn.Open();
  14. try
  15. {
  16. var tableEntity = DataCommonUtil.GetTableEntity<T>();
  17. if (!string.IsNullOrWhiteSpace(tableName))
  18. tableEntity.TableName = tableName;
  19. PropertyInfo[] properties = typeof(T).GetProperties();
  20. string[] propertyNames = properties.Select(pro => pro.Name).ToArray();
  21. string joinedPropertyNames = string.Join(", ", propertyNames);
  22. //缓存属性值访问器
  23. Func<T, object>[] propertyValue = properties.Select(pro => (Func<T, object>)pro.GetValue).ToArray();
  24. using (var writer = conn.BeginBinaryImport($"COPY {tableEntity.TableName} ({joinedPropertyNames}) FROM STDIN BINARY"))
  25. {
  26. foreach (var item in list)
  27. {
  28. writer.StartRow();
  29. foreach (var valueAccessor in propertyValue)
  30. {
  31. var fieldValue = valueAccessor(item);
  32. // 处理 null 值
  33. fieldValue = fieldValue ?? DBNull.Value;
  34. if (fieldValue == null)
  35. {
  36. writer.WriteNull();
  37. }
  38. else
  39. {
  40. writer.Write(fieldValue);
  41. }
  42. }
  43. }
  44. writer.Complete();
  45. }
  46. return true;
  47. }
  48. catch (Exception ex)
  49. {
  50. conn.Close();
  51. conn.Dispose();
  52. return false;
  53. }
  54. finally
  55. {
  56. conn.Close();
  57. conn.Dispose();
  58. }
  59. }
  60. }
  1. public static partial class BulkUtil
  2. {
  3. /// <summary>
  4. /// 判断一个类型是否为可空类型
  5. /// </summary>
  6. /// <typeparam name="T"></typeparam>
  7. /// <param name="o"></param>
  8. /// <returns></returns>
  9. public static bool IsNullable<T>(this T o)
  10. {
  11. var type = typeof(T);
  12. return type.IsNullable();
  13. }
  14. /// <summary>
  15. /// 判断一个类型是否为可空类型
  16. /// </summary>
  17. /// <typeparam name="T"></typeparam>
  18. /// <param name="type"></param>
  19. /// <returns></returns>
  20. public static bool IsNullable(this Type type)
  21. {
  22. return Nullable.GetUnderlyingType(type) != null;
  23. }
  24. /// <summary>
  25. /// 判断type是否为集合类型
  26. /// </summary>
  27. /// <param name="type"></param>
  28. /// <returns></returns>
  29. public static bool IsCollection(this Type type)
  30. {
  31. return type.GetInterfaces().Any(it => it == typeof(ICollection));
  32. }
  33. /// <summary>
  34. /// 判断type是否为迭代器类型
  35. /// </summary>
  36. /// <param name="type"></param>
  37. /// <returns></returns>
  38. public static bool IsEnumerable(this Type type)
  39. {
  40. return type.GetInterfaces().Any(it => it == typeof(IEnumerable));
  41. }
  42. /// <summary>
  43. /// 判断type是否为查询器类型
  44. /// </summary>
  45. /// <param name="type"></param>
  46. /// <returns></returns>
  47. public static bool IsQueryable(this Type type)
  48. {
  49. return type.GetInterfaces().Any(it => it == typeof(IQueryable));
  50. }
  51. /// <summary>
  52. /// 判断type是否为字符串类型
  53. /// </summary>
  54. /// <param name="type"></param>
  55. /// <returns></returns>
  56. public static bool IsString(this Type type)
  57. {
  58. return type == typeof(string);
  59. }
  60. /// <summary>
  61. /// 判断type是否为支持async的类型
  62. /// </summary>
  63. /// <param name="type"></param>
  64. /// <returns></returns>
  65. public static bool IsAsyncType(this Type type)
  66. {
  67. var awaiter = type.GetMethod("GetAwaiter");
  68. if (awaiter == null)
  69. return false;
  70. var retType = awaiter.ReturnType;
  71. //.NET Core 1.1及以下版本中没有 GetInterface 方法,为了兼容性使用 GetInterfaces
  72. if (retType.GetInterfaces().All(i => i.Name != "INotifyCompletion"))
  73. return false;
  74. if (retType.GetProperty("IsCompleted") == null)
  75. return false;
  76. if (retType.GetMethod("GetResult") == null)
  77. return false;
  78. return true;
  79. }
  80. /// <summary>
  81. /// 根据type 生成实例类型
  82. /// </summary>
  83. /// <param name="type"></param>
  84. /// <param name="args"></param>
  85. /// <returns></returns>
  86. public static object CreateInstance(this Type type, object[] args)
  87. {
  88. if (args == null || args.Length == 0)
  89. {
  90. return Activator.CreateInstance(type);
  91. }
  92. return Activator.CreateInstance(type, args: args);
  93. }
  94. /// <summary>
  95. /// 获得基础类型,获得比如被Task,ICollection<>,IEnumable<>,IQueryable<>等包裹的类型
  96. /// </summary>
  97. /// <param name="type"></param>
  98. /// <returns></returns>
  99. public static Type GetUnderlyingType(this Type type)
  100. {
  101. var resultTmp = type.IsAsyncType() ? type.GenericTypeArguments.First() : type;
  102. var resultTmp2 = resultTmp.IsGenericType
  103. ? resultTmp.GetGenericArguments().First()
  104. : resultTmp;
  105. return resultTmp2;
  106. }
  107. /// <summary>
  108. /// 根据类名获得Type实例
  109. /// </summary>
  110. /// <param name="typeName"></param>
  111. /// <returns></returns>
  112. public static Type LoadTypeByName(string typeName)
  113. {
  114. if (typeName.IsNullOrWhiteSpace()) throw new Exception("typeName must be not empty");
  115. Type t = Type.GetType(typeName);
  116. if (t != null) System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(t.TypeHandle);
  117. return t;
  118. }
  119. /// <summary>
  120. /// 获取某个类的默认值
  121. /// </summary>
  122. /// <param name="type"></param>
  123. /// <returns></returns>
  124. public static object GetDefaultValue(this Type type)
  125. {
  126. return type.IsValueType ? Activator.CreateInstance(type) : null;
  127. }
  128. /// <summary>
  129. /// 判断是否为字典类型
  130. /// </summary>
  131. /// <param name="type"></param>
  132. /// <returns></returns>
  133. public static bool IsDictionary(this Type type)
  134. {
  135. return type.GetInterfaces().Any(it => it == typeof(IDictionary));
  136. }
  137. /// <summary>
  138. /// 通过表达式树获取实体类的属性值
  139. /// </summary>
  140. /// <typeparam name="T"></typeparam>
  141. /// <typeparam name="TResult"></typeparam>
  142. /// <param name="model"></param>
  143. /// <param name="propertyName"></param>
  144. /// <returns></returns>
  145. /// <exception cref="ArgumentNullException"></exception>
  146. public static TResult GetPropertyValue<T, TResult>(this T model, string propertyName)
  147. {
  148. var result = GetPropertyValue(model, propertyName);
  149. return (TResult)result;
  150. }
  151. public static ConcurrentDictionary<string, object> CacheDictionary = new ConcurrentDictionary<string, object>();
  152. public static ConcurrentDictionary<string, Delegate> CacheDelegateDictionary = new ConcurrentDictionary<string, Delegate>();
  153. /// <summary>
  154. /// 通过表达式树获取实体类的属性值
  155. /// </summary>
  156. /// <typeparam name="T"></typeparam>
  157. /// <param name="model"></param>
  158. /// <param name="propertyName"></param>
  159. /// <returns></returns>
  160. /// <exception cref="ArgumentNullException"></exception>
  161. public static object GetPropertyValue<T>(this T model, string propertyName)
  162. {
  163. var type = model.GetType();
  164. var property = type.GetProperty(propertyName);
  165. if (property == null)
  166. {
  167. throw new ArgumentNullException($"could not find property with name {propertyName}");
  168. }
  169. var key = "get:" + type.FullName + property.Name;
  170. if (CacheDictionary.TryGetValue(key, out var func))
  171. {
  172. return ((Delegate)func).DynamicInvoke(model);
  173. }
  174. var modelExpression = Expression.Parameter(type, "model");
  175. var propertyExpression = Expression.Property(modelExpression, property);
  176. var convertExpression = Expression.Convert(propertyExpression, typeof(object));
  177. var lambda = Expression.Lambda(convertExpression, modelExpression).Compile();
  178. var result = lambda.DynamicInvoke(model);
  179. CacheDictionary.TryAdd(key, lambda);
  180. return result;
  181. }
  182. /// <summary>
  183. /// 通过表达式树设置实体类的属性值
  184. /// </summary>
  185. /// <typeparam name="T"></typeparam>
  186. /// <param name="model"></param>
  187. /// <param name="propertyName"></param>
  188. /// <param name="value"></param>
  189. /// <exception cref="ArgumentNullException"></exception>
  190. public static void SetPropertyValue<T>(this T model, string propertyName, object value)
  191. {
  192. var type = model.GetType();
  193. var property = type.GetProperty(propertyName);
  194. if (property == null)
  195. {
  196. throw new ArgumentNullException($"could not find property with name {propertyName}");
  197. }
  198. var key = "set:" + type.FullName + property.Name;
  199. if (CacheDictionary.TryGetValue(key, out var func))
  200. {
  201. ((Delegate)func).DynamicInvoke(model, value);
  202. }
  203. var modelExpression = Expression.Parameter(type, "model");
  204. var propertyExpression = Expression.Parameter(typeof(object), "val");
  205. var convertExpression = Expression.Convert(propertyExpression, property.PropertyType);
  206. var methodCallExpression = Expression.Call(modelExpression, property.GetSetMethod(), convertExpression);
  207. var lambda = Expression.Lambda(methodCallExpression, modelExpression, propertyExpression).Compile();
  208. CacheDictionary.TryAdd(key, lambda);
  209. lambda.DynamicInvoke(model, value);
  210. }
  211. /// <summary>
  212. /// 构建一个object数据转换成一维数组数据的委托
  213. /// </summary>
  214. /// <param name="objType"></param>
  215. /// <param name="propertyInfos"></param>
  216. /// <returns></returns>
  217. public static Func<T, object[]> BuildObjectGetValuesDelegate<T>(List<PropertyInfo> propertyInfos) where T : class
  218. {
  219. var objParameter = Expression.Parameter(typeof(T), "model");
  220. var selectExpressions = propertyInfos.Select(it => BuildObjectGetValueExpression(objParameter, it));
  221. var arrayExpression = Expression.NewArrayInit(typeof(object), selectExpressions);
  222. var result = Expression.Lambda<Func<T, object[]>>(arrayExpression, objParameter).Compile();
  223. return result;
  224. }
  225. /// <summary>
  226. /// 构建对象获取单个值得
  227. /// </summary>
  228. /// <param name="modelExpression"></param>
  229. /// <param name="propertyInfo"></param>
  230. /// <returns></returns>
  231. public static Expression BuildObjectGetValueExpression(ParameterExpression modelExpression, PropertyInfo propertyInfo)
  232. {
  233. var propertyExpression = Expression.Property(modelExpression, propertyInfo);
  234. var convertExpression = Expression.Convert(propertyExpression, typeof(object));
  235. return convertExpression;
  236. }
  237. /// <summary>
  238. ///
  239. /// </summary>
  240. /// <typeparam name="T"></typeparam>
  241. /// <param name="source"></param>
  242. /// <param name="propertyInfos"></param>
  243. /// <param name="useColumnAttribute"></param>
  244. /// <returns></returns>
  245. public static DataTable ToDataTable<T>(this IEnumerable<T> source, List<PropertyInfo> propertyInfos = null, bool useColumnAttribute = false) where T : class
  246. {
  247. var table = new DataTable("template");
  248. if (propertyInfos == null || propertyInfos.Count == 0)
  249. {
  250. propertyInfos = typeof(T).GetProperties().Where(it => it.CanRead).ToList();
  251. }
  252. foreach (var propertyInfo in propertyInfos)
  253. {
  254. var columnName = useColumnAttribute ? (propertyInfo.GetCustomAttribute<ColumnAttribute>()?.Name ?? propertyInfo.Name) : propertyInfo.Name;
  255. table.Columns.Add(columnName, ChangeType(propertyInfo.PropertyType));
  256. }
  257. Func<T, object[]> func;
  258. var key = typeof(T).FullName + propertyInfos.Select(it => it.Name).ToList().StringJoin();
  259. if (CacheDictionary.TryGetValue(key, out var cacheFunc))
  260. {
  261. func = (Func<T, object[]>)cacheFunc;
  262. }
  263. else
  264. {
  265. func = BuildObjectGetValuesDelegate<T>(propertyInfos);
  266. CacheDictionary.TryAdd(key, func);
  267. }
  268. foreach (var model in source)
  269. {
  270. var rowData = func(model);
  271. table.Rows.Add(rowData);
  272. }
  273. return table;
  274. }
  275. private static Type ChangeType(Type type)
  276. {
  277. if (type.IsNullable())
  278. {
  279. type = Nullable.GetUnderlyingType(type);
  280. }
  281. return type;
  282. }
  283. /// <summary>
  284. ///
  285. /// </summary>
  286. /// <param name="constructorInfo"></param>
  287. /// <returns></returns>
  288. public static Delegate BuildGenerateObjectDelegate(ConstructorInfo constructorInfo)
  289. {
  290. var parameterExpressions = new List<ParameterExpression>();
  291. foreach (var parameterInfo in constructorInfo.GetParameters())
  292. {
  293. var parameterExpression = Expression.Parameter(parameterInfo.ParameterType);
  294. parameterExpressions.Add(parameterExpression);
  295. }
  296. var c = Expression.New(constructorInfo, parameterExpressions);
  297. var lambda = Expression.Lambda(c, parameterExpressions).Compile();
  298. return lambda;
  299. }
  300. /// <summary>
  301. /// 替换dataTable里的列类型
  302. /// </summary>
  303. /// <param name="dt"></param>
  304. public static void ReplaceDataTableColumnType<OldType, NewType>(DataTable dt, Func<OldType, NewType> replaceFunc)
  305. {
  306. var needUpdateColumnIndexList = new List<int>();
  307. var needUpdateColumnNameList = new List<string>();
  308. for (int i = 0; i < dt.Columns.Count; i++)
  309. {
  310. var column = dt.Columns[i];
  311. if (column.DataType.GetUnderlyingType() == typeof(OldType))
  312. {
  313. needUpdateColumnIndexList.Add(i);
  314. needUpdateColumnNameList.Add(column.ColumnName);
  315. }
  316. }
  317. if (needUpdateColumnIndexList.Count == 0)
  318. {
  319. return;
  320. }
  321. var nameMapping = new Dictionary<string, string>();
  322. for (int i = 0; i < needUpdateColumnIndexList.Count; i++)
  323. {
  324. var oldColumnName = needUpdateColumnNameList[i];
  325. var newColumnName = Guid.NewGuid().ToString("N");
  326. nameMapping.Add(newColumnName, oldColumnName);
  327. dt.Columns.Add(newColumnName, typeof(byte[])).SetOrdinal(needUpdateColumnIndexList[i]);
  328. for (int j = 0; j < dt.Rows.Count; j++)
  329. {
  330. var c = (dt.Rows[j][oldColumnName]);
  331. dt.Rows[j][newColumnName] = replaceFunc((OldType)(dt.Rows[j][oldColumnName]));
  332. }
  333. dt.Columns.Remove(oldColumnName);
  334. }
  335. for (int i = 0; i < dt.Columns.Count; i++)
  336. {
  337. var columnName = dt.Columns[i].ColumnName;
  338. if (nameMapping.ContainsKey(columnName))
  339. {
  340. dt.Columns[i].ColumnName = nameMapping[columnName];
  341. }
  342. }
  343. }
  344. /// <summary>
  345. /// 判断字符串是否为空
  346. /// </summary>
  347. /// <param name="str"></param>
  348. /// <returns></returns>
  349. public static bool IsNullOrWhiteSpace(this string str)
  350. {
  351. return string.IsNullOrWhiteSpace(str);
  352. }
  353. /// <summary>
  354. /// 对字符串集合进行拼接
  355. /// </summary>
  356. /// <param name="source"></param>
  357. /// <param name="separator"></param>
  358. /// <returns></returns>
  359. public static string StringJoin(this IEnumerable<string> source, char separator = ',')
  360. {
  361. return string.Join(separator, source);
  362. }
  363. public static OracleDbType ConvertToOracleDbType(this Type type)
  364. {
  365. switch (Type.GetTypeCode(type))
  366. {
  367. case TypeCode.Boolean:
  368. return OracleDbType.Boolean;
  369. case TypeCode.Byte:
  370. case TypeCode.SByte:
  371. return OracleDbType.Byte;
  372. case TypeCode.Int16:
  373. case TypeCode.UInt16:
  374. return OracleDbType.Int16;
  375. case TypeCode.Int32:
  376. case TypeCode.UInt32:
  377. return OracleDbType.Int32;
  378. case TypeCode.Int64:
  379. case TypeCode.UInt64:
  380. return OracleDbType.Int64;
  381. case TypeCode.Single:
  382. return OracleDbType.Single;
  383. case TypeCode.Double:
  384. return OracleDbType.Double;
  385. case TypeCode.Decimal:
  386. return OracleDbType.Decimal;
  387. case TypeCode.String:
  388. return OracleDbType.NVarchar2;
  389. case TypeCode.Char:
  390. return OracleDbType.Char;
  391. case TypeCode.DateTime:
  392. return OracleDbType.Date;
  393. case TypeCode.Object:
  394. if (type == typeof(Guid))
  395. {
  396. return OracleDbType.Raw;
  397. }
  398. else if (type == typeof(byte[]))
  399. {
  400. return OracleDbType.Blob;
  401. }
  402. else if (type == typeof(TimeSpan))
  403. {
  404. return OracleDbType.IntervalDS;
  405. }
  406. else if (type == typeof(OracleClob))
  407. {
  408. return OracleDbType.Clob;
  409. }
  410. else if (type == typeof(OracleBlob))
  411. {
  412. return OracleDbType.Blob;
  413. }
  414. else if (type == typeof(OracleXmlType))
  415. {
  416. return OracleDbType.XmlType;
  417. }
  418. else if (type == typeof(OracleRefCursor))
  419. {
  420. return OracleDbType.RefCursor;
  421. }
  422. else if (type == typeof(OracleTimeStamp))
  423. {
  424. return OracleDbType.TimeStamp;
  425. }
  426. else if (type == typeof(OracleIntervalYM))
  427. {
  428. return OracleDbType.IntervalYM;
  429. }
  430. else if (type == typeof(OracleIntervalDS))
  431. {
  432. return OracleDbType.IntervalDS;
  433. }
  434. else if (type == typeof(OracleCollectionType))
  435. {
  436. return OracleDbType.Object;
  437. }
  438. else
  439. {
  440. return OracleDbType.Varchar2;
  441. }
  442. default:
  443. return OracleDbType.Varchar2;
  444. }
  445. }
  446. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/871247
推荐阅读
相关标签
  

闽ICP备14008679号