Create PROCEDURE pageTest
(
@FirstID nvarchar(
@LastID nvarchar(
@isNext bit=null
@allCount int output
@pageSize int output
@CurPage int
)
AS
if @CurPage=
begin
select @allCount=count(ProductId) from Product_test
set @pageSize=
select top
ProductId
ProductName
Introduction
from Product_test order by ProductId
end
else if @CurPage=
select * from
(select top
ProductName
Introduction
from Product_test order by ProductId desc ) as aa
order by ProductId
else
begin
if @isNext=
select top
ProductName
Introduction
from Product_test where ProductId > @LastID order by ProductId
else
select * from
(select top
ProductName
Introduction
from Product_test where ProductId < @FirstID order by ProductId desc) as bb order by ProductId
end
**************************************************************************
CREATE OR REPLACE PROCEDURE TABLEPAGE_SELECT(v_page_size int
v_current_page int
v_table_name varchar
v_order_field varchar
v_order_sequence varchar
p_cursor OUT refcursor_pkg
v_sql varchar
v_sql_count varchar
v_sql_order varchar
v_count int;
v_endrownum int;
v_startrownum int;
BEGIN
if v_order_field!=
v_sql_order :=
else
v_sql_order :=
end if;
v_sql_count:=
execute immediate v_sql_count into v_count;
if v_order_sequence=
v_endrownum:=v_count
v_startrownum:=v_endrownum
else
v_endrownum:= v_current_page * v_page_size;
v_startrownum := v_endrownum
end if;
v_sql :=
to_char(v_endrownum) ||
to_char(v_startrownum)||
open p_cursor for v_sql;
END TABLEPAGE_SELECT;
From:http://tw.wingwit.com/Article/program/Oracle/201311/17677.html