Oracle数据库返回cursor问题的解决方法

来源:未知 责任编辑:责任编辑 发表时间:2015-09-16 20:04 点击:

这篇论坛文章(赛迪网技术社区)着重介绍了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数据库下使用iSQL*Plus DBA访问数据库
  • oracle 让sys用户可以使用isqlplus
  • Oracle数据库Constraint约束的常用操作及异常处理
  • ORACLE10gr2数据导入MySQL方案
  • OCP043第十五讲 Database Security
  • export/import的使用
  • Oracle行列转换小结
  • Table函数使用简介
  • Bulk Collect性能分析(zz)
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1