oracle通用分页存储过程
A. oracle数据库怎么实现分页,且每页三条数据
您好:oracle查询分页可分为两种情况,一种使用的是rownum ,另外一种则是使用 row_number() over(order by column_name desc)。
1.使用rownum分页查询,可用以下方式:
select t2.* from (select t1.*,rownum as rn from table_name t1 where 1=1 and rownum <= page * page_size) t2 where t2.rn > (page - 1) * page_size;
2.使用 row_number() over() 分页查询
select t2.* from (select t1.*,row_number() over(order by column_name desc) as rn from table_name t1 where 1=1 )t2 where t2.rn > (page-1)* page_size and t2.rn <= page * page_size;
这种方式,也是可以分页的。
希望能帮助您!
B. oracle存储过程的分页
调用的时候这样
declare
ocur tespackage.test_cursor;
v_count int:=0;
v_pagecount int :=0;
v_out int;
begin
fenye('table1',20,1,v_count,v_pagecount,ocur);
loop
fetch ocur into v_out ;
exit when ocur%notfound ;
dbms_output.put_line('count='||v_count);
end loop;
end ;
/
C. oracle:写一个用于分页的存储过程.调用的时候可以传参
select
*
from
(select
a.*,rownum
r
from
(select
*
from
table_a)
a
where
rownum<=b)
where
r>=a
该sql语句实现了分页查询。
其中table_a表示你要查询的那张表,r>=a,rownum<=b中的a和b表示需要查询的记录的起止数。
需要做分页的话,上面的b可以改成currentPage*pageCount,a可以改成(currentPage-1)*pageCount,
currentPage表示当前页数,pageCount表示总页数