Oracle实现的分页(存储过程)

以前,这是我在百度上博客的文章,决定搬过来啦,发现这里的论坛很不错,希望大家多多指教。

create or replace package page_package as
type page_cursor is ref cursor;
end page_package;

create or replace procedure pageModel
(page_now in number,
page_size in number,
table_name in varchar2,
row_count out number,
page_count out number,
rs_list out page_package.page_cursor
) is
v_sql varchar2(1000);
v_begin number:=(page_now-1)*page_size+1;
v_end number:=page_size*page_now;
begin
      v_sql:='select * from (select rownum r,t.* from (select * from '||table_name||') t where rownum<='||v_end||') where r>='||v_begin;
      open rs_list for v_sql;
      v_sql:='select count(*) from '||table_name;
      execute immediate v_sql into row_count;--立即执行此SQL语句,并将结果赋给row_count
      if mod(row_count,page_size)=0 then
         page_count:=row_count/page_size;
      else
         page_count:=row_count/page_size+1;
	  close rs_list;
      end if;
end;

 

 

你可能感兴趣的:(oracle,sql,百度)