CREATE OR REPLACE PROCEDURE TABLEPAGE_SELECT(v_page_size int, --the size of a page of list
v_current_page int, --the current page of list
v_table_name varchar2, --the talbe name
v_order_field varchar2,--the order field
v_order_sequence varchar2,--the order sequence should by "_desc"or "_asc",_is blank.
--v_sql_select varchar2, --the select sql for procedure
--v_sql_count varchar2, --the count sql for procedure
--v_out_recordcount OUT int, --the num of return rows
p_cursor OUT refcursor_pkg.return_cursor) as
v_sql varchar2(3000); --the sql for select all rows of list
v_sql_count varchar2(3000); --the count sql for procedure
v_sql_order varchar2(2000); --the order of list
v_count int; -- the amount rows fo original list
v_endrownum int; --the end row num of the current page
v_startrownum int; --the start row num of the current page
BEGIN
----set the order of list
if v_order_field!='NO' then
v_sql_order :=' ORDER BY '|| v_order_field ||' '||v_order_sequence;
else
v_sql_order :='';
end if;
----catch the amount rows of list
v_sql_count:='SELECT COUNT(ROWNUM) FROM '||v_table_name;
execute immediate v_sql_count into v_count;
-- v_out_recordcount := v_count;
----set the value of start and end row
if v_order_sequence='desc' then
v_endrownum:=v_count-(v_current_page-1)*v_page_size;
v_startrownum:=v_endrownum - v_page_size + 1;
else
v_endrownum:= v_current_page * v_page_size;
v_startrownum := v_endrownum - v_page_size + 1;
end if;
----the sql for page slide
v_sql := 'SELECT * FROM (SELECT '||v_table_name||'.*, rownum rn FROM '||v_table_name||' WHERE rownum <= ' ||
to_char(v_endrownum) ||' '|| v_sql_order||') WHERE rn >= ' ||
to_char(v_startrownum)||' '||v_sql_order;
open p_cursor for v_sql;
END TABLEPAGE_SELECT;
分享到:
相关推荐
Oracle分页存储过程,里面包含C#调用代码实例;
在分页存储过程中,主要理解了变量的动态赋值和输入输出参数的使用就非常简单了 下面为调用方法: var c_Preccount number; var c_Ppagecount number; var c_cur refcursor; exec proc_SpPag(1,'SELECT * FROM T_...
高效多条件 Oracle 分页存储过程 ,快速分页
终极版 分页存储过程 高效 条件 排序 Oracle
oracle 分页 存储过程,超级牛的分页存储过程,执行后可以直接实用,分页速度刚刚的
Oracle 分页存储过程 SQL Oracle 分页存储过程 SQL
教你如何在oracle 中创建分页的存储过程
java调用oracle分页存储过程,存储过程保存在sql文件夹下,可以直接运行。 实现了输入表名、每页显示记录数、当前页、排序字段,返回总记录数,总页数,和结果集。
功能说明 写好oracle的连接字符串和查询语句,调用程序中的方法可以很方便的实现分页功能。该方法中,将参数连接字符串,查询的sql语句,... 效率不是很高,如有高人写出很厉害的分页存储过程,希望您与大家分享。
几乎每一个WEB应用都会用到分页,因此,将其做得通用高效就变得非常重要了,根据自己的想法用存储过程做了一个分页的存储过程,与大家分享,希望能够通过讨论得到更好的解决方案。 --之所以用存储过程,是因为以后...
NULL 博文链接:https://kaka100.iteye.com/blog/803218
Oracle分页存储过程,根据指定条件分页 并附上使用示例(C#代码) 注:不能查询视图或者包含distinct、group by、inner join的子句