博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

返回数据集的存储过程比较..........

Posted on 2007-06-18 17:46  jisen  阅读(1605)  评论(0编辑  收藏  举报

在sql server2000中,存储过程只要有单独的sql语句,通过C#调用该存储过程,用适配器fill数据集(DataSet)数据集中的表的个数和存储过程中的单独运行的sql语句个数一一对应。
CREATE PROCEDURE jisentest
 @qwtgw VARCHAR(16),
 @aaa int,
 @abc varchar(16) out
AS

delete DisTest where  [Name] = @qwtgw;
set @abc = '11322321';
select * from DisTest;
select * from DisTest;
select * from DisTest;
return  1;
GO
C#调用该存储过程后数据集中会有3个DataTable
在Oracle中想返回数据集却没有这么简单,找了资料,好像只能借助游标才能返回数据集(目前还不知道一个存储过程输出多个游标的情况。)
要先创建一个包声明,在包声明中
create or replace package jisen.test
is
type Cur_Type is ref cursor;
procedure PageProcedure(
sqltext in varchar2,
 PageCount in number,
 PageNumber in number,
 sqlcondition in varchar2,
 iCount out number,
 mycs out Cur_Type);
end;
其次创建包主体,包主体中包含声明中的存储过程的实现
create or replace package body jisen.test
is
procedure PageProcedure
(sqltext in varchar2,
 PageCount in number,
 PageNumber in number,
 sqlcondition in varchar2,
 iCount out number,
 mycs out Cur_Type
 )
 as
 tempsql varchar2(2000);
 bbegin number(10);
 bend number(10);
 Find_rs_cur Cur_Type;
 begin

 if sqlcondition is null then
 begin
 tempsql := 'select count(*) from (' || sqltext ||')';
 end;
 elsif length(sqlcondition) > 0 then
 begin
 tempsql := 'select count(*) from (' || sqltext || ') where ' || sqlcondition;
 end;
 else
 begin
 tempsql := 'select count(*) from (' || sqltext ||')';
 end;
 end if;
 execute immediate tempsql into iCount;

 bbegin := PageCount*PageNumber;
 bend := (PageNumber + 1)*PageCount;
 
 tempsql := 'select * from (
        select rownum as tempA,t.* from ('
  || sqltext || ') t  where rownum < ' || bend || ')
   where tempA >= ' || bbegin  ;
  open Find_rs_cur for tempsql;
  mycs := Find_rs_cur;
  --execute immediate tempsql;用该语句从C#中得不到查询结果.
 end PageProcedure;
end pk_wt;
该存储过程中是使用rownum进行分页.
不知道高手们有没有比较简单的返回数据集的存储过程?还忘赐教!