zoukankan      html  css  js  c++  java
  • Oracle笔记:分页查询

    查询前三条记录:

    select * from (select a1.*,rownum rn from (select * from emp) a1 where rownum<=3);

    查询第三到六条记录:

    select * from (select a1.*,rownum rn from (select * from emp) a1 where rownum<=6) where rn>3;

    如要指定查询列,排序等,只需修改最里层的子查询.

    编写分页存储过程

    --编写一个存储过程,要求可以输入表名、每页显示记录数、当前页、
    --返回总记录数、总页数和返回的结果集。
    create or replace package test_package as
    type test_cursor is ref cursor;
    end test_package;

    create or replace procedure paging
    (tableName in varchar2,   --表名
    recordPerPage in number,  --每页显示记录数
    currentPage in number,    --当前页
    totalRecord out number,   --总记录数
    totalPage out number,    --总页数
    t_cursor out test_package.test_cursor  --返回的结果集
    ) is  
    v_sql varchar2(1000);
    v_start number:=(currentPage-1)*recordPerPage+1;
    v_end number:=currentPage*recordPerPage;
    begin
    v_sql:='select * from (select a1.*,rownum rn from (select * from '||tableName
    ||') a1 where rownum<='||v_end||') where rn>='||v_start;
    open t_cursor for v_sql;
    v_sql:='select count(*) from '||tableName;
    --获得总记录数
    execute immediate v_sql into totalRecord;
    --计算总页数
    if mod(totalRecord,recordPerPage)=0 then
      totalPage :=totalRecord/recordPerPage;
    else
      totalPage :=totalRecord/recordPerPage+1;
    end if;
    close t_cursor;
    end;

  • 相关阅读:
    js中this的用法
    js原型链与继承(初体验)
    关于C语言指针中的p++与p+i
    react todolist
    react表单提交
    react条件渲染
    react初体验
    初次接触express
    阿里内推在线编程题(返回元素的选择器)
    模块初始化
  • 原文地址:https://www.cnblogs.com/testing/p/2987933.html
Copyright © 2011-2022 走看看