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;

  • 相关阅读:
    第八次作业 8、特征选择
    第六次作业 6.逻辑归回
    MySQL5.7详细配置教程
    MySQL5.1安装与卸载教程
    常用的正则表达式
    MongoDB安装以及配置教程
    机器学习:4.K均值算法--应用
    利用Python制作二维码
    机器学习:15 手写数字识别-小数据集
    机器学习:14 深度学习-卷积
  • 原文地址:https://www.cnblogs.com/testing/p/2987933.html
Copyright © 2011-2022 走看看