Code
create or replace package datapager
is
type dataType is ref cursor;
procedure userPager(myType out datatype ,--游标变量
pageSize in number ,--页面大小,一页显示几行,共显示几页
pageNumber in number, --显示第几页
tableName in varchar2,--表名
isOrderBy in varchar2,--是否排序
isDesc in varchar2, --是否降序
fieldName in varchar2 --排序字段名称
);
end;
create or replace package body datapager
is
procedure userPager(myType out datatype ,--游标变量
pageSize in number ,--页面大小,一页显示几行,共显示几页
pageNumber in number, --显示第几页
tableName in varchar2, --表名
isOrderBy in varchar2,--是否排序
isDesc in varchar2, --是否降序
fieldName in varchar2 --排序字段名称
)
as
pageCount number; --一共多少页
pagenumber2 number;
tblsql varchar2(500); --产生执行sql
begin
select count(*)/pageSize into pageCount from aspnet_users; --算出多少页
pagenumber2:=pageNumber;
pagenumber2 :=pagenumber2-1;
--如果要跳转的页面大于 总页数 则 为总页数
if pageNumber>pageCount then pagenumber2 := pageCount;
end if;
tblsql :='select * from (select s.*,rownum as rnn from (select t.* ,rownum as rn from '||tableName||' t';
--判断是否排序
if isOrderBy ='True' then tblsql:= tblsql || ' order by '||fieldName;
end if;
--判断是否有降序
if isDesc ='True' then tblsql := tblsql ||' desc ) s';
end if;
tblsql := tblsql ||') where rnn between '||(pagenumber2*pagesize+1) ||' and '||(pagenumber2*pageSize + pageSize) ;
dbms_output.put_line(tblsql);
open myType for tblsql;
end userpager;
end datapager;
create or replace package datapager
is
type dataType is ref cursor;
procedure userPager(myType out datatype ,--游标变量
pageSize in number ,--页面大小,一页显示几行,共显示几页
pageNumber in number, --显示第几页
tableName in varchar2,--表名
isOrderBy in varchar2,--是否排序
isDesc in varchar2, --是否降序
fieldName in varchar2 --排序字段名称
);
end;
create or replace package body datapager
is
procedure userPager(myType out datatype ,--游标变量
pageSize in number ,--页面大小,一页显示几行,共显示几页
pageNumber in number, --显示第几页
tableName in varchar2, --表名
isOrderBy in varchar2,--是否排序
isDesc in varchar2, --是否降序
fieldName in varchar2 --排序字段名称
)
as
pageCount number; --一共多少页
pagenumber2 number;
tblsql varchar2(500); --产生执行sql
begin
select count(*)/pageSize into pageCount from aspnet_users; --算出多少页
pagenumber2:=pageNumber;
pagenumber2 :=pagenumber2-1;
--如果要跳转的页面大于 总页数 则 为总页数
if pageNumber>pageCount then pagenumber2 := pageCount;
end if;
tblsql :='select * from (select s.*,rownum as rnn from (select t.* ,rownum as rn from '||tableName||' t';
--判断是否排序
if isOrderBy ='True' then tblsql:= tblsql || ' order by '||fieldName;
end if;
--判断是否有降序
if isDesc ='True' then tblsql := tblsql ||' desc ) s';
end if;
tblsql := tblsql ||') where rnn between '||(pagenumber2*pagesize+1) ||' and '||(pagenumber2*pageSize + pageSize) ;
dbms_output.put_line(tblsql);
open myType for tblsql;
end userpager;
end datapager;