首页 / ORACLE / Oracle中的数据分页
Oracle中的数据分页
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Oracle中的数据分页,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2889字,纯文字阅读大概需要5分钟。
内容图文
--数据分页脚本
--创建包含数据分页代码元素声明的包头结构
create or replace package data_control
is
type type_cursor_data is ref cursor;
v_totalline int; --总数据行数
v_totalpage int; --总页数
v_selectsql varchar2(500); --缓存查询语句
--function pagedata(tablename varchar2,currentpage int,linecount int) return type_cursor_data; --函数方式实现分页查询
procedure pagedata(tablename varchar2,currentpage int,linecount int,resultdata out type_cursor_data); --过程方式实现分页查询
end data_control;
--创建针对数据分页代码元素实现的包体结构
create or replace package body data_control
is
/*function pagedata(tablename varchar2,currentpage int,linecount int) return type_cursor_data
is
data type_cursor_data; --缓存当前页数据的游标变量
begin
execute immediate ‘select count(*) from ‘ || tablename into v_totalline;
dbms_output.put_line(‘总记录行数: ‘ || v_totalLine);
if v_totalline / linecount = 0 then
v_totalpage := v_totalline / linecount;
else
v_totalpage := v_totalline / linecount + 1;
end if;
dbms_output.put_line(‘总页数: ‘ || v_totalPage);
v_selectsql := ‘select * from (select tn.*,rownum linenum from ‘ || tablename || ‘ tn) t where t.linenum > ‘ || (currentpage * linecount - linecount) || ‘ and t.linenum <= ‘ || (currentpage * linecount);
open data for v_selectsql;
return data;
end pagedata;*/
procedure pagedata(tablename varchar2,currentpage int,linecount int,resultdata out type_cursor_data)
is
data type_cursor_data; --缓存当前页数据的游标变量
begin
execute immediate ‘select count(*) from ‘ || tablename into v_totalline;
dbms_output.put_line(‘总记录行数: ‘ || v_totalLine);
if v_totalline / linecount = 0 then
v_totalpage := v_totalline / linecount;
else
v_totalpage := v_totalline / linecount + 1;
end if;
dbms_output.put_line(‘总页数: ‘ || v_totalPage);
v_selectsql := ‘select * from (select tn.*,rownum linenum from ‘ || tablename || ‘ tn) t where t.linenum > ‘ || (currentpage * linecount - linecount) || ‘ and t.linenum <= ‘ || (currentpage * linecount);
open data for v_selectsql;
resultdata := data;
end pagedata;
end data_control;
--测试代码
declare
res_data data_control.type_cursor_data;
type type_page_record is record(
empno emp.empno%type,
ename emp.ename%type,
job emp.job%type,
mgr emp.mgr%type,
hiredate emp.hiredate%type,
sal emp.sal%type,
comm emp.comm%type,
deptno emp.deptno%type,
rn int
);
rec_row type_page_record;
begin
--res_data := data_control.pagedata(‘emp‘,2,5);
data_control.pagedata(‘dept‘,2,5,res_data);
loop
fetch res_data into rec_row;
exit when res_data%notfound;
dbms_output.put_line(rec_row.ename);
end loop;
close res_data;
end;
Oracle中的数据分页
标签:
本文系统来源:http://www.cnblogs.com/hgc-bky/p/5588430.html
内容总结
以上是互联网集市为您收集整理的Oracle中的数据分页全部内容,希望文章能够帮你解决Oracle中的数据分页所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。