分页的存储过程

create or replace PROCEDURE  PROCEDURE1
(
--输入参数
currentPage IN INT, --当前页
pagerows IN INT, --每页行数

--输出参数
totalpages OUT INT, --总的页数
totalrows OUT INT, --总的条数
hasnext OUT INT, --是否有下一页
hasprovious OUT INT,--是否有上一页
c_emp out c_cursor09.mytype--游标(先在包中定义ref游标)
) AS
currentrows int;
BEGIN
  --得到总的条数
  select count(*)  into totalrows from emp;
 
  --经过判断得到总页数
  if mod(totalrows,pagerows)=0 then
    totalpages:=totalrows/pagerows;
  else
    totalpages:=totalrows/pagerows+1;
  end if;
 
  --是否上一页
  if currentpage=1 then
    hasprovious:=0;
  else
    hasprovious:=1;
  end if;
 
  --是否下一页
  if currentpage=totalpages then
    hasnext:=0;
  else
    hasnext:=1;
  end if;
 
  --rownum从1开始所以currentrows需要加1
  currentrows:=currentpage*pagerows-pageRows+1;
 
  open c_emp for
  select empno from (select rownum r,emp.* from emp)
  where r<currentrows+pagerows and r>=currentrows;
 
END;
 

你可能感兴趣的:(C++,c,C#)