请问 在做数据量大的分页存储过程的时候 这个存储过程 是多表联合查询的 大慨 5张表左右吧
     请问这个时候该怎么做!? 我的目的是要做成通用的 请高手给我一个简单例子即可 我自己摸索! 不胜感激~

解决方案 »

  1.   

        是的 就是说是这样的 现在不是有很多 这样的吗
         
    select top 页大小 * 
    from table1 
    where id> 
          (select max (id) from 
          (select top ((页码-1)*页大小) id from table1 order by id) as T) order by id 
         
    这个里面只是对单表进行查询啊
      如果我的SQL 语句是类似这样的
         
    select f.username, h.loginname,h.getIntegral,h.useIntegral,m.remainintegral,m.usergrade,m.integralstate,f.customerid from (select sum(decode(sign(a.integral),'1',a.integral,0)) as getIntegral,sum(decode(sign(a.integral),'-1',a.integral,0)) as useIntegral,b.loginName from CTM_IntegralRec a left join CTM_Information b on a.customerid=b.customerId where a.cid=7001 group by b.loginname ) hright join (select c.username, c.customerid, c.loginname, c.provinceId,c.cityid,d.provinceName,d.cityname from CTM_Information cleft join CDE_City d on c.provinceId =d.provinceid and c.cityid=d.cityid where 1=1 and cid=7001) f on h.loginname=f.loginname  right join Pan_UserIntegralInfo m on m.customersn = f.customerid where 1=1 and  h.getIntegral > 0
          的多表连接查询 那这个不能达到一个通用的效果了
      所以....   
      

  2.   

    将要连接的表和连接条件作为传参..我觉得不是个好主意
    可以试试建个过程,将分组字段,排序字段,页大小和页码作为条件传入
    你先建好视图view1
    执行这个存储过程对这个视图进行分页查询,生成视图view2
    查询view2得到你要的结果
      

  3.   

    select top 页大小 *

    这个是MSSQL的
      

  4.   

    CREATE OR REPLACE PACKAGE BODY "GETPAGING" is
     Procedure Pagination
     (
      pageSize       in   number,          --每页记录数
      pageIndex      in   number,          --页码
      sourceName     in   varchar2,        --表  名
      FieldStr       in   varchar2,        --字段集
      primaryKey     in   varchar2,        --主键
      sourceFilter   in   varchar2,        --过滤条件
      sourceSort     in   varchar2,        --排序集
      sourceSortDir  in   number,          --排序方式0:不排序;1:升序;2:降序
      TotalCount     out  number,          --总记录数
      Cur_ReturnCur  out  T_CURSOR
      )
      is
      l_MinRowNum      number;               --分页小值
      l_MaxRowNum      number;               --分页大值
      l_SortStr        varchar2(100);         --排序
      l_SourceWhere    varchar2(1000);       --Where条件
      l_TotalCount     number;               --总记录数
      l_sql            varchar2(1000);       --动态sql
      l_sql2           varchar2(1000);       --动态sql
      begin
      l_MinRowNum:=pageSize*(pageIndex-1);
      l_MaxRowNum:=pageSize*pageIndex;  if sourceSortDir=1 then
         if upper(sourceSort) = upper(primaryKey) then
            l_SortStr:=' order by '||sourceSort||' asc';
         else
            l_SortStr:=' order by '||sourceSort||' asc,'||primaryKey;
         end if;
      end if;
      if sourceSortDir=2 then
         if upper(sourceSort) = upper(primaryKey) then
            l_SortStr:=' order by '||sourceSort||' desc';
         else
            l_SortStr:=' order by '||sourceSort||' desc,'||primaryKey;
         end if;
      end if;  if sourceFilter is NULL then
         l_SourceWhere:='';
      else
         l_SourceWhere:=' where ' || sourceFilter;
      end if;
      
      l_sql:='(select '|| FieldStr ||' from '|| sourceName ||') Source1';
      l_sql2:='select count(*) as TotalCount from '|| l_sql||' '|| l_SourceWhere;
      execute immediate l_sql2 into l_TotalCount;
      TotalCount:=l_TotalCount;
        l_sql2:='select * from '|| l_sql ||' '|| l_SourceWhere ||' '|| l_SortStr ;
      if (l_TotalCount>0) then
         if (l_TotalCount>pageSize) then        
            l_sql2:='select * from '|| l_sql ||' '|| l_SourceWhere ||' '|| l_SortStr ;
            if (pageIndex=1) then
               l_sql2:='select Source2.* from ('|| l_sql2 ||') Source2 where rownum<='||pageSize;
            else
               l_sql2:='select Source2.*,rownum as RowIndex from ('|| l_sql2 ||') Source2';
               l_sql2:='select Source3.* from ('|| l_sql2 ||') Source3 where RowIndex>'||l_MinRowNum||' and RowIndex<='||l_MaxRowNum;           
            end if;
         end if;
      end if;
      open Cur_ReturnCur for l_sql2; 
      end Pagination;
    end GetPaging;
      

  5.   

    明白这位的意思 你的意思是把 view1 当作条件 来传入view2.... 这样一步一步的来得到最后结果
      我刚才也正准备问 那不是要建立多个视图 看来这个问题解决了 
    我想问一下 各位自己做的项目里面也是这种做法吗  我的意思是方法只有这一种?