网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > Oracle教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.打破oracle数据库树立的种种神话.
.Oracle数据库字符集转换规律全面.
.ORACLE在HP-UX下的系列问题处理(.
.程式初始化设定档.
.经典Oracle图书推荐-之三.
.sp_addlinkersrvlogin从oracle查.
.Oracle RAC on Veritas DBE/AC(S.
.ExactPapers Oracle 1Z0-023 200.
.Oracle9i的简化SQL语法.
.ORACLE9I中外部表的使用.
.如何限制只有0组的用户可以su成r.
.使用exp工具进行数据库备份及恢复.
.企业级N Tier体系结构解决方案讨.
.简单提高ORACLE数据库的查询统计.
.在异种机之间实现数据库迁移.
.关于Oracle 9i 跳跃式索引扫描(I.
.Oracle经验集锦(1).
.Enterprise Library-Data Block .
.使用oracle pipe传递消息.
.Oracle 8i数据库体系结构.

Enterprise Library-Data Block oracle

发表日期:2008-2-9



  昨天使用 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;
  
  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;
  
  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();

上一篇:在JAVA中连接Oracle数据库(例子) 人气:741
下一篇:在Java中调用Oracle的过程和函数 人气:882
浏览全部Oracle教程的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐