日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

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

發布時間:2024/1/17 asp.net 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .NET调用Oracle存储过程,使用数组类型的参数(如ArrayList) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天一個項目組的朋友問及:如何在.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 objectcmd.CommandText = "insert into dept(deptno) values (:deptno)";cmd.Connection = con;// Set the ArrayBindCount to indicate the number of valuescmd.ArrayBindCount = 3;// Create a parameter for the array operationsOracleParameter prm = new OracleParameter("deptno", OracleDbType.Int32);prm.Direction = ParameterDirection.Input;prm.Value = myArrayDeptNo;// Add the parameter to the parameter collectioncmd.Parameters.Add(prm);// Execute the commandcmd.ExecuteNonQuery();Console.WriteLine("Insert Completed Successfully");// Close and Dispose OracleConnection objectcon.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.

The following example demonstrates error handling for array binding:

? /* Database Setup connect scott/tiger@oracle drop table depttest; create table depttest(deptno number(2)); */// C#using System; using System.Data; using Oracle.DataAccess.Client; class ArrayBindExceptionSample {static void Main(){OracleConnection con = new OracleConnection();con.ConnectionString = "User Id=scott;Password=tiger;Data Source=oracle;";con.Open();OracleCommand cmd = new OracleCommand();// Start a transactionOracleTransaction txn = con.BeginTransaction(IsolationLevel.ReadCommitted);try{int[] myArrayDeptNo = new int[3] { 10, 200000, 30 };// int[] myArrayDeptNo = new int[3]{ 10,20,30};// Set the command text on an OracleCommand objectcmd.CommandText = "insert into depttest(deptno) values (:deptno)";cmd.Connection = con;// Set the ArrayBindCount to indicate the number of valuescmd.ArrayBindCount = 3;// Create a parameter for the array operationsOracleParameter prm = new OracleParameter("deptno", OracleDbType.Int32);prm.Direction = ParameterDirection.Input;prm.Value = myArrayDeptNo;// Add the parameter to the parameter collectioncmd.Parameters.Add(prm);// Execute the commandcmd.ExecuteNonQuery();}catch (OracleException e){Console.WriteLine("OracleException {0} occured", e.Message);if (e.Number == 24381)for (int i = 0; i < e.Errors.Count; i++)Console.WriteLine("Array Bind Error {0} occured at Row Number {1}", e.Errors[i].Message, e.Errors[i].ArrayBindIndex);txn.Commit();}cmd.Parameters.Clear();cmd.CommandText = "select count(*) from depttest";decimal rows = (decimal)cmd.ExecuteScalar();Console.WriteLine("{0} row have been inserted", rows);con.Close();con.Dispose();} }

See Also:

"ArrayBindIndex"?for more information

OracleParameterStatus Enumeration Types

Table: OracleParameterStatus Members?lists?OracleParameterStatus?enumeration values.

OracleParameterStatus Members

Member Names?
Description

Success
For input parameters, indicates that the input value has been assigned to the column.

For output parameters, indicates that the provider assigned an intact value to the parameter.

NullFetched
Indicates that a?NULL?value has been fetched from a column or an?OUT?parameter.

NullInsert
Indicates that a?NULL?value is to be inserted into a column.

Truncation
Indicates that truncation has occurred when fetching the data from the column.

Statement Caching

Statement caching eliminates the need to parse each SQL or PL/SQL statement before execution by caching server cursors created during the initial statement execution. Subsequent executions of the same statement can reuse the parsed information from the cursor, and then execute the statement without reparsing, for better performance.

In order to see performance gains from statement caching, Oracle recommends caching only those statements that will be repeatedly executed. Furthermore, SQL or PL/SQL statements should use parameters rather than literal values. Doing so takes full advantage of statement caching, because parsed information from parameterized statements can be reused even if the parameter values change in subsequent executions. However, if the literal values in the statements are different, the parsed information cannot be reused unless the subsequent statements also have the same literal values.

Statement Caching Connection String Attributes

The following connection string attributes control the behavior of the ODP.NET statement caching feature:

  • Statement?Cache?Size

    This attribute enables or disables ODP.NET statement caching. By default, this attribute is set to?0?(disabled). If it is set to a value greater than?0, ODP.NET statement caching is enabled and the value specifies the maximum number of statements that can be cached for a connection. Once a connection has cached up to the specified maximum cache size, the cursor least recently used is freed to make room to cache the newly created cursor.

  • Statement?Cache?Purge

    This attribute provides a way for connections to purge all statements that are cached when a connection is closed or placed back into the connection pool. By default, this attribute is set to?false, which means that cursors are not freed when connections are placed back into the pool.

Enabling Statement Caching through the Registry

To enable statement caching by default for all ODP.NET applications running in a system, without changing the application, set the registry key of?HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOMEID\ODP.NET\StatementCacheSize?to a value greater than?0. (ID?is the appropriate Oracle Home ID.) This value specifies the number of cursors that are to be cached on the server. By default, it is set to?0.

Statement Caching Methods and Properties

The following property and method are relevant only when statement caching is enabled:

  • OracleCommand.AddToStatementCache?property

    If statement caching is enabled, having this property set to?true?(default) adds statements to the cache when they are executed. If statement caching is disabled or if this property is set to?false, the executed statement is not cached.

  • OracleConnection.PurgeStatementCache?method

    This method purges all the cached statements by closing all open cursors on the database that are associated with the particular connection. Note that statement caching remains enabled after this call.

Connections and Statement Caching

Statement caching is managed separately for each connection. Therefore, executing the same statement on different connections requires parsing once for each connection and caching a separate cursor for each connection.

Pooling and Statement Caching

Pooling and statement caching can be used in conjunction. If connection pooling is enabled and the?Statement?Cache?Purge?attribute is set to?false, statements executed on each separate connection are cached throughout the lifetime of the pooled connection.If the?Statement?Cache?Purge?attribute is set to?true, all the cached cursors are freed when the connection is placed back into the pool. When connection pooling is disabled, cursors are cached during the lifetime of the connection, but the cursors are closed when the?OracleConnection?object is closed or disposed of.?



本文轉自斯克迪亞博客園博客,原文鏈接:http://www.cnblogs.com/sgsoft/archive/2007/04/13/712261.html,如需轉載請自行聯系原作者

總結

以上是生活随笔為你收集整理的.NET调用Oracle存储过程,使用数组类型的参数(如ArrayList)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: japanesexxxx日本妞 | 女的高潮流时喷水图片大全 | 国产一区二区三区视频在线播放 | 男人资源网站 | 黄色国产一级片 | 福利所第一导航 | 超碰人操| 91精品国产99久久久久久红楼 | 久久久18禁一区二区三区精品 | 欧美日韩黄色大片 | 国产a√精品区二区三区四区 | 在线电影一区二区 | 免费国产视频 | 欧美xxxx性xxxxx高清 | 日本不卡一区二区三区 | 东方成人av在线 | heyzo在线播放 | 欧美拍拍 | 好吊操视频这里只有精品 | 国产一级在线 | 福利在线免费观看 | 少妇熟女高潮流白浆 | 亚洲色精品三区二区一区 | 久久久久人妻一区精品色 | 亚洲精品乱码久久久久 | 国模无码视频一区二区三区 | 天堂在线91| 国产精品麻豆成人av电影艾秋 | 在线观看免费www | 亚洲av无码乱码在线观看富二代 | 欧美透逼视频 | 欧美黑人xxx | 欧美日韩在线观看一区二区三区 | 日本黄色aaa| www.成人.com| 不卡日本 | 少妇高潮一区二区三区69 | 欧美肥老妇视频 | www.毛片com | 中国国产毛片 | 美女被叉叉的影院 | 日韩成人动漫在线观看 | 99在线观看 | 久久成人精品 | 国产伦理精品 | 欧美黄色大片免费观看 | 久久激情小说 | 国产伦理一区二区 | 99视频只有精品 | 国产精品美女一区二区 | 久久九九热视频 | 亚洲国产精品久久人人爱 | 38在线视频 | 色666| 成年人看的视频网站 | 国产美女精品视频国产 | 日本成人在线免费视频 | 亚洲一区二区在线免费观看 | 99精品视频国产 | 国产亚洲精品成人无码精品网站 | 老司机精品福利导航 | 日韩一区二区影视 | 大帝av| 国产在线观看免费视频今夜 | 免费在线看黄视频 | 欧美日韩专区 | 91在线最新 | 中文字幕一区二区三区四区五区 | 九九视频免费在线观看 | 毛片看看 | 综合亚洲色图 | 一区二区中文字幕 | 一区二区三区四区不卡 | 欧美性天堂 | 日本高清久久 | 黄色av网址在线观看 | 波多野结衣之潜藏淫欲 | 免费处女在线破视频 | 久久久久久国产精品三区 | 天天爽夜夜爽一区二区三区 | 按摩害羞主妇中文字幕 | 最新中文字幕2019 | 欧美videos另类精品 | 萌白酱一区二区 | 亚洲男人天堂久久 | 久草在在线视频 | 永久视频在线 | 日本在线一区二区 | 色女孩综合 | 牛牛视频在线观看 | 国产精品亚洲二区在线观看 | 久久精品一区二区三区不卡牛牛 | 色资源在线| 日韩毛片无码永久免费看 | 无码人妻丰满熟妇区bbbbxxxx | 日韩av免费在线看 | 日本xxxx高潮少妇 | 91嫩草视频在线观看 | 卡通动漫亚洲综合 |