国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Oracle數據庫返回cursor問題的解決方法

瀏覽:152日期:2023-11-22 19:31:25

這篇論壇文章(賽迪網技術社區)著重介紹了Oracle數據庫返回cursor問題的解決方法,詳細內容請參考下文:

昨天使用 Data Block 操作 oracle 返回 cursor 。期間產生了一點問題,很是郁悶,找了一下午也沒有解決。早上睡不著,起來繼續找。結果找到了解決的方法。其實也是怪自己沒有很好的看文檔。在此記錄一下。以使別的同志再出現我的問題的時候,很容易的找到解決的方法。

問題是這樣的:

我在oracle里面有這樣一個過程

PROCEDURE ListAllStatic_Users (cur_Static_User OUT T_CURSOR)

IS

BEGIN

OPEN cur_Static_User FOR

Select * FROM Static_User ;

END ListAllStatic_Users;

我在程序里面如下調用:

Database db = DatabaseFactory.CreateDatabase('oraserver');

string sqlCommand = 'Static_UserPackage.ListAllStatic_Users';

DBCommandWrapper dbCommandWrapper =db.GetStoredProcCommandWrapper(sqlCommand);

DataSet dsCustomers = db.ExecuteDataSet(dbCommandWrapper);

DataGrid1.DataSource=dsCstomers;

DataGrid1.DataBind();

結果出現如下問題:

ORA-06550: 第 1 行, 第 7 列: PLS-00306: 調用 'LISTALLSTATIC_USERS' 時參數個數或類型錯誤 orA-06550: 第 1 行, 第 7 列: PL/SQL: Statement ignored

說明: 執行當前 Web 請求期間,出現未處理的異常。請檢查堆棧跟蹤信息,以了解有關該錯誤以及代碼中導致錯誤的出處的詳細信息。

異常詳細信息: System.Data.OracleClient.OracleException: orA-06550: 第 1 行, 第 7 列: PLS-00306: 調用 'LISTALLSTATIC_USERS' 時參數個數或類型錯誤 orA-06550: 第 1 行, 第 7 列: PL/SQL: Statement ignored

源錯誤:

行 44:

行 45: DataSet dsCustomers = db.ExecuteDataSet(dbCommandWrapper);行 46: DataGrid1.DataSource=dsCustomers;

行 47: DataGrid1.DataBind();

我以為是我的參數沒有弄對,于是就加了一句:

dbCommandWrapper.AddOutParameter('cur_Static_User',DbType.Object,500);

結果還是一樣的。后來也試驗了

OracleCommandWrapper.AddParameter(string,DbType,int,ParameterDirection,bool,byte,byte,string,DataRowVersion,object);

這個方法來添加,也是不行。

后來就上網找了很長時間也沒有什么進展。今天早上起來,還是一籌莫展,偶爾的打開Enterprise Library安裝目錄的Enterprise Library Release Notes.rtf文件,發現里面有這么一段

2.4 Data Access Application Block: Default oracle cursor cur_OUT

The managed provider for oracle requires you to explicitly bind your reference cursor in your parameter collection. This means you must explicitly create an output parameter for the cursor in your application code. However, that code will not be portable with database systems that do not require a parameter for the cursor. The oracleDatabase allows you to create commands without specifying a cursor. It will create a cursor, named cur_OUT, for commands that execute a stored procedure and do not include an output parameter for the cursor. This means that you can name your reference cursor as 'cur_OUT' and the Data Access Application Block will bind it for you; you do not need to explicitly create an output parameter for the cursor. If your stored procedures use a cursor with a name other than 'cur_OUT,' you must explicitly add a parameter for each cursor to the command. Similarly, if your stored procedure contains multiple cursors, you must explicitly add each cursor parameter to the command.

這下我就明白了。在我的oracle函數中,我的名字 cur_Static_User 和默認的名字cur_OUT不匹配。

于是我就改了我的存儲過程的參數名稱,cur_Static_User改為 cur_OUT。

問題就解決了。

經過試驗,也可以用如下方法用自己的參數名,而不用默認的參數名。

也可以,在一個PROCEDURE中返回多個 CURSOR

我的存儲過程:

Procedure STATIC_USER_SelectAll

( cur_OUT_f OUT T_OUT, cur_OUT_g OUT T_OUT)

AS

Begin

OPEN cur_OUT_f FOR Select * from STATIC_USER;

OPEN cur_OUT_g FOR Select * from STATIC_ROLE;

End;

代碼如下:

Database db = DatabaseFactory.CreateDatabase('oraserver');

string sqlCommand = 'Static_UserPackage.STATIC_USER_SelectAll';

Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleCommandWrapper dbCommandWrapper =(Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleCommandWrapper)db.GetStoredProcCommandWrapper(sqlCommand);

dbCommandWrapper.AddParameter('cur_OUT_f', OracleType.Cursor, 0, ParameterDirection.Output, true, 0, 0, String.Empty, DataRowVersion.Default, Convert.DBNull);

dbCommandWrapper.AddParameter('cur_OUT_g', OracleType.Cursor, 0, ParameterDirection.Output, true, 0, 0, String.Empty, DataRowVersion.Default, Convert.DBNull);

DataSet dsCustomers = db.ExecuteDataSet(dbCommandWrapper);

DataGrid1.DataSource=dsCustomers.Tables[0];

DataGrid1.DataBind();

DataGrid2.DataSource=dsCustomers.Tables[1];

DataGrid2.DataBind();

標簽: Oracle 數據庫
主站蜘蛛池模板: 偷拍精品视频一区二区三区 | 欧美日韩成人 | 欧美巨大video粗暴 | 精品欧美高清一区二区免费 | 99久热在线精品视频播 | 日韩欧美综合在线二区三区 | 亚洲精品一级一区二区三区 | 午夜嘿咻| 国产亚洲欧美成人久久片 | 成人免费看毛片 | 91久久亚洲国产成人精品性色 | 国产一区二区不卡 | 亚洲线精品久久一区二区三区 | 作爱视频在线免费观看 | 伊人久久精品午夜 | 性做久久久久久免费观看 | 免费永久国产在线视频 | 欧美日本一区二区三区生 | 欧美一级二级片 | 狠狠五月深爱婷婷网 | 国产亚洲欧美日韩在线观看一区二区 | 欧美一级专区免费大片野外交 | 成人午夜精品 | 中国一级毛片欧美一级毛片 | 俄罗斯小屁孩cao大人免费 | 亚洲欧美自拍偷拍 | 91九色国产 | 在线观看黄网视频免费播放 | 91亚洲综合| 日韩在线二区 | 国产高清区 | 99久久精品视香蕉蕉er热资源 | 亚洲在线精品视频 | 97香蕉久久夜色精品国产 | 中文字幕在线网址 | 国产成人一区二区三区免费观看 | 手机看黄av免费网址 | 欧美嫩交| 国产农村乱子伦精品视频 | 怡红院免费播放全部视频 | 韩国女主播青草在线观看 |