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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

dotConnect for Oracle入门指南(八):通过OracleCommand类使用存储过

發(fā)布時間:2025/4/5 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 dotConnect for Oracle入门指南(八):通过OracleCommand类使用存储过 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

【下載dotConnect for Oracle最新版本】

dotConnect for Oracle(原名OraDirect.NET)建立在ADO.NET技術上,為基于Oracle數(shù)據(jù)庫的應用程序提供完整的解決方案。它為設計應用程序結構帶來了新的方法,提高工作效率,使數(shù)據(jù)庫應用程序的開發(fā)更簡便。

本篇文章介紹如何在OracleCommand類的幫助下,使用Dotconnect for Oracle創(chuàng)建和使用Oracle存儲過程和函數(shù)。

有兩種通過OracleCommand執(zhí)行存儲過程的一般方法。

第一種方法是將過程調用包含到PL/SQL塊中,并通過將其放入OracleCommand.CommandText屬性來執(zhí)行該塊。在這種情況下,該過程返回的數(shù)據(jù)可以在同一塊中立即處理。如果過程需要一些參數(shù),則應將它們添加到OracleCommand.Parameters集合中。此方法與通常的命令執(zhí)行沒有區(qū)別。

第二種方法是將OracleCommand.CommandType設置為System.Data.commandType.StoredProcedure。在這種情況下,CommandText應該設置為過程的名稱。以下示例顯示如何使用上一節(jié)中的get-all-depts-proc過程填充數(shù)據(jù)表:

123456789101112131415161718192021222324// Open the connectionOracleConnection connection????=?new OracleConnection("Server=Ora; User Id=Scott; Password = tiger;");connection.Open();// Create a commandOracleCommand command =?new OracleCommand();command.Connection = connection;// Set the CommandType property to execute// stored procedures or functions by this commandcommand.CommandType = System.Data.CommandType.StoredProcedure;// Set the name of procedure or function to be executedcommand.CommandText =?"get_all_depts_proc";// The ParameterCheck property should be true to automatically// check the parameters needed for the procedure execution.command.ParameterCheck =?true;// At this moment, the command is ready for execution.// As we have an output cursor parameter, we may use the command to fill a data table.OracleDataTable dt =?new OracleDataTable(command, connection);dt.Fill();
12345678910111213141516171819202122Dim connection _????As New OracleConnection("Server=Ora; User Id=Scott; Password = tiger;")connection.Open()' Create a command.Dim command =?New OracleCommand()command.Connection = connection' Set the CommandType property to execute stored procedures or functions by this command.command.CommandType = System.Data.CommandType.StoredProcedure' Set the name of procedure or function to be executed.command.CommandText =?"get_all_depts_proc"' The ParameterCheck property should be true to automatically' check the parameters needed for the procedure execution.command.ParameterCheck =?True' At this moment, the command is ready for execution.' As we have an output cursor parameter, we may use the command to fill a data table.Dim dt =?New OracleDataTable(command, connection)dt.Fill()

將CommandText設置為“get-all-depts-func”,相同的代碼使用存儲函數(shù)而不是過程填充數(shù)據(jù)表。

優(yōu)化存儲過程執(zhí)行

當執(zhí)行ExecuteReader或ExecuteEscalar時,并且OracleCommand.CommandType設置為System.Data.commandType.StoredProcedure時,默認情況下將執(zhí)行附加查詢,以檢查過程是否是流水線的,如果不是,則說明參數(shù)(簽出光標參數(shù))。這允許您在僅設置必要的過程參數(shù)后執(zhí)行存儲過程,而不必費心完全正確地填充參數(shù)集合,因為在獲取元數(shù)據(jù)后,它將自動填充。

但是,執(zhí)行附加查詢可能不合適,并且在某些情況下可能會導致性能損失。Dotconnect for Oracle允許使用DescribeStoredProcedure連接字符串參數(shù)禁用此檢查。

如果只將此連接字符串參數(shù)設置為false,OracleCommand將執(zhí)行存儲的例程,而不進行任何額外的檢查。在這種情況下,例程不能是表值函數(shù),它的所有參數(shù)都必須手動設置。

如果要在不進行其他檢查的情況下執(zhí)行表值函數(shù),則需要將OracleCommand的IsTableValuedFunction屬性設置為true。這允許您在不進行額外檢查的情況下執(zhí)行表值函數(shù)。將此屬性設置為true也是執(zhí)行非管道表值函數(shù)的唯一方法。即使describeStoredProcedure設置為true,也必須將IsTableValuedFunction設置為true才能執(zhí)行非管道表值函數(shù)。

如果只對OracleCommand的單個實例禁用附加檢查,而不禁用連接的附加檢查,請將IsTableValuedFunction屬性(根據(jù)執(zhí)行的函數(shù)是否為表值,設置為true或false)和ImplicitRefCursors屬性設置為false。設置IsTableValuedFunction屬性將禁用檢查執(zhí)行的函數(shù)是否為表值,并將ImplicitRefCursors屬性設置為false將禁用檢查其他光標參數(shù)。


轉載于:https://blog.51cto.com/14048826/2346066

總結

以上是生活随笔為你收集整理的dotConnect for Oracle入门指南(八):通过OracleCommand类使用存储过的全部內容,希望文章能夠幫你解決所遇到的問題。

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