Oracle中的数据分页

--数据分页脚本

--创建包含数据分页代码元素声明的包头结构
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;

时间: 2024-08-03 21:52:22

Oracle中的数据分页的相关文章

MyBatis在Oracle中插入数据并返回主键的问题解决

引言:  在MyBatis中,希望在Oracle中插入数据之时,同时返回主键值,而非插入的条数... 环境:MyBatis 3.2 , Oracle, Spring 3.2   SQL Snippet in XML Configuration: <insert id="insertSelective" parameterType="com.jxxx.p2pp.model.UUserInfo"> <selectKey resultType="

MySQL与Oracle中的基本分页

MySQL中的基本分页: select ename from emp where xxxxx order by sal  desc limit (pageno-1)*pageSize,pageSize; Oracle中的基本分页 select tt.* from ( select t.*,rownum as  linenum from (select  * from  tbl_role) t where rownum <#{0}*#{1} )tt where linenum  >(#{0}-1

oracle中的数据对象

oracle中的数据对象有表.视图.索引.序列等 表的相关操作 1.创建表 方式一: 方式二:create table person( create table person1 id number(18), as name varchar2(5), select * from person age number(3), sex varchar2(4) ); 2.删除表 方式一:只会删除表中的内容,不会删除表结构truncate delete 方式二:删除表结构truncate table per

实现数据在前台动态显示之分页的实现(将DataSet中的数据分页显示)

在实现前台动态显示数据时有多种方法,但使用到将DataSet中的数据分页这一方法时发现很多地方都能用得到,在这里记录一下. /// <summary> /// 分页的实现(将DataSet中的数据分页显示) /// </summary> /// <param name="ds"></param> /// <returns></returns> public DataSet SplitDataSet() { Data

Sqoop_具体总结 使用Sqoop将HDFS/Hive/HBase与MySQL/Oracle中的数据相互导入、导出

一.使用Sqoop将MySQL中的数据导入到HDFS/Hive/HBase 二.使用Sqoop将HDFS/Hive/HBase中的数据导出到MySQL 2.3 HBase中的数据导出到mysql 眼下没有直接的命令将HBase中的数据导出到MySQL.但能够先将HBase中的数据导出到HDFS中.再将数据导出到MySQL. 三.使用Sqoop将Oracle中的数据导入到HDFS/Hive/HBase 以下仅仅给出将Oracle中的数据导入HBase,其它情况下的命令行选项与MySQL的操作相似

详细总结 使用Sqoop将HDFS/Hive/HBase与MySQL/Oracle中的数据相互导入、导出

一.使用Sqoop将MySQL中的数据导入到HDFS/Hive/HBase 二.使用Sqoop将HDFS/Hive/HBase中的数据导出到MySQL 2.3 HBase中的数据导出到mysql 目前没有直接的命令将HBase中的数据导出到MySQL,但可以先将HBase中的数据导出到HDFS中,再将数据导出到MySQL. 三.使用Sqoop将Oracle中的数据导入到HDFS/Hive/HBase 下面只给出将Oracle中的数据导入HBase,其他情况下的命令行选项与MySQL的操作相似 O

在Oracle中更新数据时,抛出:ORA-01008: not all variables bound

在Oracle中更新数据时,抛出了一个 :ORA-01008 not all variables bound, 我的理解是不是所有的变量/参数都有边界,不懂: 后来知道了,原来是“不是所有变量/参数都确定”, 就是有些变量没有指定,缺少变量参数, 最后发现是因为在写三层时少写了一个"new OracleParameter(":ID",userinfo.ID);" 导致的.

如何用Excel直接查询Oracle中的数据(转)

将Oracle中查询的数据保存为Excel文件,通常使用的是PL/SQL Developer. 其实,Excel可直接写SQL语句查询Oracle中数据,在这里,用到ODBC驱动.详细步骤如下: 一.配置ODBC数据源 开始->控制面板->系统和安全->管理工具->ODBC数据源(可根据自己的情况选择32位还是64位). 因本机安装的是Oracle 11.2.0.4 64位,故选择ODBC数据源(64位),显示如下: 点击“添加”,选择“Oracle in OraDb11g_hom

Oracle中读取数据一些原理研究

文章很多摘录了 http://blog.163.com/[email protected]/blog/static/7956964020131069843572/ 同时基于这篇文章的基础上,补充一些学习要点,如有问题,希望指出探讨. 1 ORACLE体系结构 下图描述了oracle的体系结构.SGA(system global area)是各个进程共享的内存块,Buffer cache用来缓存数据文件的数据块(block). 2 如何在data buffer中查找数据块 data buffer存