国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Oracle數(shù)據(jù)庫(kù)返回cursor問題的解決方法

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

這篇論壇文章(賽迪網(wǎng)技術(shù)社區(qū))著重介紹了Oracle數(shù)據(jù)庫(kù)返回cursor問題的解決方法,詳細(xì)內(nèi)容請(qǐng)參考下文:

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

問題是這樣的:

我在oracle里面有這樣一個(gè)過程

PROCEDURE ListAllStatic_Users (cur_Static_User OUT T_CURSOR)

IS

BEGIN

OPEN cur_Static_User FOR

Select * FROM Static_User ;

END ListAllStatic_Users;

我在程序里面如下調(diào)用:

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();

結(jié)果出現(xiàn)如下問題:

ORA-06550: 第 1 行, 第 7 列: PLS-00306: 調(diào)用 'LISTALLSTATIC_USERS' 時(shí)參數(shù)個(gè)數(shù)或類型錯(cuò)誤 orA-06550: 第 1 行, 第 7 列: PL/SQL: Statement ignored

說明: 執(zhí)行當(dāng)前 Web 請(qǐng)求期間,出現(xiàn)未處理的異常。請(qǐng)檢查堆棧跟蹤信息,以了解有關(guān)該錯(cuò)誤以及代碼中導(dǎo)致錯(cuò)誤的出處的詳細(xì)信息。

異常詳細(xì)信息: System.Data.OracleClient.OracleException: orA-06550: 第 1 行, 第 7 列: PLS-00306: 調(diào)用 'LISTALLSTATIC_USERS' 時(shí)參數(shù)個(gè)數(shù)或類型錯(cuò)誤 orA-06550: 第 1 行, 第 7 列: PL/SQL: Statement ignored

源錯(cuò)誤:

行 44:

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

行 47: DataGrid1.DataBind();

我以為是我的參數(shù)沒有弄對(duì),于是就加了一句:

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

結(jié)果還是一樣的。后來也試驗(yàn)了

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

這個(gè)方法來添加,也是不行。

后來就上網(wǎng)找了很長(zhǎng)時(shí)間也沒有什么進(jìn)展。今天早上起來,還是一籌莫展,偶爾的打開Enterprise Library安裝目錄的Enterprise Library Release Notes.rtf文件,發(fā)現(xiàn)里面有這么一段

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函數(shù)中,我的名字 cur_Static_User 和默認(rèn)的名字cur_OUT不匹配。

于是我就改了我的存儲(chǔ)過程的參數(shù)名稱,cur_Static_User改為 cur_OUT。

問題就解決了。

經(jīng)過試驗(yàn),也可以用如下方法用自己的參數(shù)名,而不用默認(rèn)的參數(shù)名。

也可以,在一個(gè)PROCEDURE中返回多個(gè) CURSOR

我的存儲(chǔ)過程:

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();

主站蜘蛛池模板: 留坝县| 筠连县| 朔州市| 宁晋县| 铜鼓县| 红安县| 麦盖提县| 平陆县| 连南| 沅江市| 井研县| 南召县| 阳曲县| 信阳市| 南开区| 西充县| 延边| 平昌县| 锦州市| 吴旗县| 澳门| 花莲市| 永安市| 临沭县| 丰县| 合江县| 察雅县| 阳山县| 固镇县| 化德县| 洞头县| 永寿县| 浏阳市| 广水市| 正镶白旗| 开平市| 望都县| 明光市| 桂阳县| 从化市| 张家界市|