Linux中国  设为主页
 收藏本站
 
当前位置: > 首页 ->数据库应用 ->Oracle ->.NET调用Oracle存储过程,使用数组类型的参数(如ArrayList)
  相关分类: 
Access
DB2
Mysql
Oracle
PostgreSQL
SQL Server
Sybase
其他数据库
  站内搜索: 
热门文章排行
热门文章排行 Oracle 10gR2 RAC + RHEL AS4U2 (04-22)
深刻理解Oracle数据库的启动和关闭(04-17)
设计和实施Oracle RAC项目 (04-23)
Oracle XQuery查询、构建和转换XML (04-23)
分享:我的oracle9i学习笔记 (04-23)
精采文章排行
精采文章排行 怎样保持Oracle数据优良性能的若干诀(06-29)
讲解基于Oracle高性能动态SQL程序开(06-29)
如何恢复只有完好数据文件的Oracle数(06-29)
八个学习点帮助你全面认识Oracle数据(06-29)
轻松六步使你的Oracle存储过程迅速加(06-29)
  ·浅析Oracle数据库的最大可用性体系结构 ·在Oracle 9i中Form Builder使用树心得 ·Oracle 9i应用COMPOSE和UNISTR创建沉音 ·Oracle巧取指定记录以及巧用外关联查询 ·快速掌握Oracle数据库游标的使用方法 ·你对Oracle数据库字符集究竟认识多少? ·讲解Oracle数据库之中数据安全完全分析 ·讲解Oracle数据库中LONG类型字段的存取 ·Oracle数据库中创建表时怎样考虑列顺序

.NET调用Oracle存储过程,使用数组类型的参数(如ArrayList)

作者:Webmaster   来源:Linuxdby.com   点击:   日期:2007-06-03 [收藏] [投稿]

  IE是否经常中毒?推荐您

今天一个项目组的朋友问及:如何在.NET中调用Oracle的存储过程,并以数组作为参数输入。

Oracle的PL/SQL非常强大,支持定长数组和变长数组,支持任何自定义数据类型。通过阅读ODP的文档,发现Oracle是完全支持将数组作为存储过程参数的。下面给出文档信息。

Array Binding
The array bind feature enables applications to bind arrays of a type using the OracleParameter class. Using the array bind feature, an application can insert multiple rows into a table in a single database round-trip.

The following example inserts three rows into the Dept table with a single database round-trip. The OracleCommand ArrayBindCount property defines the number of elements of the array to use when executing the statement.

 
// C#
 
using System;
using System.Data;
using Oracle.DataAccess.Client;
 
class ArrayBindSample
{
  static void Main()
  {
    OracleConnection con = new OracleConnection();
    con.ConnectionString = "User Id=scott;Password=tiger;Data Source=oracle;";
    con.Open();
    Console.WriteLine("Connected successfully");
 
    int[] myArrayDeptNo = new int[3] { 10, 20, 30 };
    OracleCommand cmd = new OracleCommand();
 
    // Set the command text on an OracleCommand object
    cmd.CommandText = "insert into dept(deptno) values (:deptno)";
    cmd.Connection = con;
 
    // Set the ArrayBindCount to indicate the number of values
    cmd.ArrayBindCount = 3;
 
    // Create a parameter for the array operations
    OracleParameter prm = new OracleParameter("deptno", OracleDbType.Int32);
 
    prm.Direction = ParameterDirection.Input;
    prm.Value = myArrayDeptNo;
 
    // Add the parameter to the parameter collection
    cmd.Parameters.Add(prm);
 
    // Execute the command
    cmd.ExecuteNonQuery();
    Console.WriteLine("Insert Completed Successfully");
 
    // Close and Dispose OracleConnection object
    con.Close();
    con.Dispose();
  }
}


See Also:

"Value" for more information


OracleParameter Array Bind Properties
The OracleParameter class provides two properties for granular control when using the array bind feature:

ArrayBindSize

The ArrayBindSize property is an array of integers specifying the maximum size for each corresponding value in an array. The ArrayBindSize property is similar to the Size property of an OracleParameter object, except the ArrayBindSize property specifies the size for each value in an array.

Before the execution, the application must populate the ArrayBindSize property; after the execution, ODP.NET populates it.

The ArrayBindSize property is used only for parameter types that have variable length such as Clob, Blob, and Varchar2. The size is represented in bytes for binary datatypes, and characters for the Unicode string types. The count for string types does not include the terminating character. The size is inferred from the actual size of the value, if it is not explicitly set. For an output parameter, the size of each value is set by ODP.NET. The ArrayBindSize property is ignored for fixed-length datatypes.

ArrayBindStatus

The ArrayBindStatus property is an array of OracleParameterStatus values that specify the status of each corresponding value in an array for a parameter. This property is similar to the Status property of the OracleParameter object, except that the ArrayBindStatus property specifies the status for each array value.

Before the execution, the application must populate the ArrayBindStatus property. After the execution, ODP.NET populates the property. Before the execution, an application using the ArrayBindStatus property can specify a NULL value for the corresponding element in the array for a parameter. After the execution, ODP.NET populates the ArrayBindStatus property, indicating whether the corresponding element in the array has a null value, or if data truncation occurred when the value was fetched.


Error Handling for Array Binding
If an error occurs during an array bind execution, it can be difficult to determine which element in the Value property caused the error. ODP.NET provides a way to determine the row where the error occurred, making it easier to find the element in the row that caused the error.

When an OracleException object is thrown during an array bind execution, the OracleErrorCollection object contains one or more OracleError objects. Each of these OracleError objects represents an individual error that occurred during the execution, and contains a provider-specific property, ArrayBindIndex, which indicates the row number at which the error occurred.

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<

上一页12 3 下一页

上一篇:oracle OCCI 的一个简单的包装类的实现   下一篇:oracle修改计算机名后重启服务失败解决办法
文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论

   相关文章:
·迅速安装Linux与Oracle数据库步骤精讲

   文章评论:(1条)
  
 请留名: 匿名评论   点击查看所有评论 论坛讨论
 

 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。