ALTER PROCEDURE dbo.Sp_TeamInfo_FetchTeam@pageindex int--第N页as
declare @pagesize int
set @pagesize=25
declare @docount bigint
select @docount=count(*) from TeamView  
if @docount=@pagesize
select * from TeamView 
else
begin
declare @indextable table(id int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
insert into @indextable(nid) select id from TeamView
select a.* from TeamView a,@indextable t where a.id=t.nid
and t.id>@PageLowerBound and t.id<=@PageUpperBound 
end

解决方案 »

  1.   

    你这里返回的好像是记录集,在sql server中可以这样吗?在oracle中不知能否实现,如果可以,输出参数应该是这个类型的吧:type tabletype is table of TeamView%rowtype index by binary_integer;只有请教高手了:)
      

  2.   

    SqlServer 可以直接在存储过程直接用Select ,就会自动返回记录集感觉Sqlserver用起来要方便些
      

  3.   

    这个是Java写的Sqlserver和Oracle分页,希望能给你一个参考:://--到制定的页的Sql
        public String On(int prmPgeNo) throws SQLException
        {
           //**基础信息处理***************
            //--页数处理
            if (prmPgeNo<=0)
            {
                prmPgeNo=1;
            }
            //--取得页数和总记录数
            this.GetPgeCountAndRcdcount();        if (prmPgeNo > this.PgeCount)
            {
                prmPgeNo= this.PgeCount;
            }
            this.PgeNo = prmPgeNo;        int frtSeltop=this.perPgeRows*prmPgeNo;
            //--检查是否到了最后一个页
            int scdSeltop=this.perPgeRows;
            if (prmPgeNo==this.PgeCount)
            {
                scdSeltop=this.RcdCount-this.perPgeRows*(this.PgeCount-1);
            }      //*****************      //**取得Sql语句,根据不同的数据库方式
            String strSql="";
            //--如果是Oracle
            if (this.DbType.equals("oracle"))
            {
               int startrow = this.perPgeRows*(prmPgeNo-1);  //开始的记录号
               int endrow = this.perPgeRows*(prmPgeNo); //结束的记录号           String SqlPge="Select "+this.FldLst+" From "+this.TbName+" Where "+this.SelWhr+" ";           strSql="SELECT "+this.FldLst+" from "+this.TbName+" Where "+this.SelWhr+" order by "+this.FirstSortFlds+" ";
               strSql="select RowNum rid,A.* from ( "+strSql+") A WHERE RowNum<="+endrow;
               strSql="select * from ("+strSql+") where rid>"+startrow;
            }
            //--如果是Sqlserver
    else if (this.DbType.equals("sqlserver"))
            {
                strSql="select * from (select top "+scdSeltop+" "+this.OverFldLst+" from (select top "+frtSeltop+" "+this.FldLst+" from "+this.TbName+" where "+this.SelWhr+"  order by "+this.FirstSortFlds +" ) T order by "+this.SecendSortFlds+" desc ) A order by "+this.SecendSortFlds+" desc ";
                
                this.ErrMsg=strSql;
            }
            return strSql;
        }