通用ORACLE 分页查询语句,存储过程实现

来源:互联网 发布:php获取cookie 编辑:程序博客网 时间:2024/05/24 15:42

PROCEDURE RECORDS_LIST
  (

      sqlrecords in varchar2,
   sqlrecordscount in varchar2,
   cur_result_out out serarch_result,
   totalcount out int,
   curpage in  int,
   perpage in int,
   icurpage out int,
   totalpage out int
  )
  IS
  startno int;
  endno int;
  tempno float;
  BEGIN
     execute immediate sqlrecordscount into totalcount;
  --tempno := (totalcount+perpage-1)*1.00/perpage*1.00;
  --tempno := mod(totalcount,perpage);
  totalpage := ceil(totalcount/perpage);
  icurpage := curpage;
  if curpage > totalpage then
      icurpage := totalpage;
     elsif curpage < 1 then
      icurpage := 1;
  end if;
  startno := (icurpage-1)*perpage+1;
  endno := icurpage*perpage;
   dbms_output.put_line('select * from (select rownum row_num,a.* from (');
   dbms_output.put_line(') a ) where row_num between ');
   dbms_output.put_line(startno);
   dbms_output.put_line(' and ');
   dbms_output.put_line(endno);
  open cur_result_out for 'select * from (select rownum row_num,a.* from ('||sqlrecords||') a ) where row_num between '||startno||' and '||endno;
     --open cur_result_out for sqlpersons;
  EXCEPTION
       WHEN others THEN
          raise;
  END RECORDS_LIST;

原创粉丝点击