Home >Database >Mysql Tutorial >oracle存储过程分页代码

oracle存储过程分页代码

PHP中文网
PHP中文网Original
2016-06-07 15:02:431105browse

欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 oracle存储过程分页代码是怎么实现的,我们来看下中国IT实验小编为您整理的方法吧! /*******存储过程分页代码**********/ --包头 create or replace package pck_my is type c_my is ref cursor; pr

 

欢迎进入Oracle社区论坛,与200万技术人员互动交流  >>进入

  oracle存储过程分页代码是怎么实现的,我们来看下中国IT实验小编为您整理的方法吧!

  /*******存储过程分页代码**********/

  --包头

  create or replace package pck_my is

  type c_my is ref cursor;

  procedure page_moed(

  v_table in varchar2, --表名

  current_page in out number,--当前页

  pageSize in out number,--页行数

  total out number,--总行数

  countPage out number,--总页数

  c_cursor out pck_my.c_my--游标

  );

  end pck_my;

  --body

  create or replace package body pck_my as

  procedure page_moed(

  v_table in varchar2,

  current_page in out number,

  pageSize in out number,

  total out number,

  countPage out number,

  c_cursor out pck_my.c_my

  )is

  v_sql varchar2(1000);

  v_max number;

  v_min number;

  e_table exception;

  begin

  --判断参数

  if v_table is null then

  raise e_table;

  --return;

  end if;

  if current_page is null then

  current_page:=1;

  end if;

  if pageSize<=0 then

  pageSize:=5;

  end if;

  --计算 最大行 最小行

  v_max:=(current_page+1)*pageSize;

  v_min:=current_page*pageSize;

  --获取数据

  v_sql:= 'select *

  from (select filminfo.*, rownum as t from '|| v_table ||' where rownum <='|| v_max||')

  where t > ' ||v_min;

  open c_cursor for v_sql;

  --计算总行数

  v_sql:='select count(*) from '|| v_table;

  execute immediate v_sql into total;

  --计算总页数

  if mod(total,pageSize)=0 then

  countPage:=total/pageSize;

  else

  countPage:=total/pageSize+1;

  end if;

  --exception

  exception

  when e_table then

  dbms_output.put_line('表名不能为空');

  end;

  end pck_my;

  -- exet

  select * from filminfo


[1] [2] 


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn