oracle 分页 很棒的sql语句

来源:asp之家 时间:2009-07-02 11:44:00 

CREATE OR REPLACE PROCEDURE PROC6338196642095312503719(输入新闻主题 Varchar2,输入新闻内容 Varchar2,输入发布时间 Varchar2,输入当前页码 Number,输入每页行数 Number,输出当前页码 OUT Number,输出总行行数 OUT Number,输出总页页数 OUT Number,输入是否下页 Number,输入新闻编号 Varchar2,RETURN_CURSOR OUT CUSTOMTYPE.MYRCTYPE)
--功能描述:
--编写人:
--编写日期:
--如果返回结果集,必须使用自定义游标Return_Cursor
IS --OR AS
--变量定义区
v_cPageCount integer; -- 要显示的数据总行数
v_cPage integer; -- 要显示数据的当前页
BEGIN
--存储过程主体
if 输入新闻编号 is null then
begin
--- 输出总行行数
select max(rownum) into 输出总行行数 from(
select * from xtnews where 1=1
and 输入新闻主题 is null or (输入新闻主题 is not null and V_XWZT like '%'||输入新闻主题||'%')
and 输入发布时间 is null or (输入发布时间 is not null and D_FBSJ = to_date(输入发布时间,'yyyy-mm-dd'))
)where 输入新闻内容 is null or (输入新闻内容 is not null and V_XWNR like '%'||输入新闻内容||'%');
-- 输出总页页数
select ceil(输出总行行数/输入每页行数) into 输出总页页数 from dual;
exception when no_data_found then
null;
end;
-- 计算 输入当前页码 要显示的数据总行数
if 输入当前页码 is not null then
-- xia一页
if 输入是否下页 = 1 then
-- 计算 获取数据的当前页
v_cPage := (输入当前页码 + 1);
-- 最后一页
if v_cPage > 输出总页页数 then
v_cPage := 输出总页页数;
end if;
end if;
-- shang一页
if 输入是否下页 = 0 then
-- 计算 获取数据的当前页
v_cPage := (输入当前页码 - 1);
-- 最前一页
if v_cPage = 0 then
v_cPage := 1;
end if;
end if;
-- 要显示的数据总行数
v_cPageCount := v_cPage * 输入每页行数;
end if;
end if;
-- 执行查询 获取 要显示的数据
begin
open return_cursor for
select nts.* from(
select nt.* from (
select rownum 序号,n.* from(
select * from(
select * from(
select
I_ID 新闻编号,
V_XWZT 新闻主题,
V_XWNR 新闻内容,
D_FBSJ 发布时间,
D_YXSJ 有效时间,
V_FBBM 发布部门
from xtnews
where 1=1 and 输入新闻主题 is null or (输入新闻主题 is not null and V_XWZT like '%'||输入新闻主题||'%')
)where 输入新闻内容 is null or (输入新闻内容 is not null and 新闻内容 like '%'||输入新闻内容||'%')
)where 输入发布时间 is null or (输入发布时间 is not null and 发布时间 = to_date(输入发布时间,'yyyy-mm-dd'))
)n where 输入新闻编号 is null or (输入新闻编号 is not null and 新闻编号 = 输入新闻编号)
order by rownum
)nt where nt.序号 <= v_cPageCount order by 序号 desc
)nts where nts.序号 > (v_cPageCount-输入每页行数) order by 序号;
exception when no_data_found then
null;
end;
-- 输出最后计算的当前页码
if 输入新闻编号 is null and v_cPage is not null then
输出当前页码 := v_cPage;
end if;
END;

标签:oracle,分页
0
投稿

猜你喜欢

  • asp全面解析Server对象

    2008-10-19 17:24:00
  • Web标准之路 勿使用W3C废弃的元素

    2009-07-13 12:25:00
  • div不换行,css不换行,自动换行

    2009-09-07 12:52:00
  • 关于 Flash Banner 设计的建议

    2010-02-02 18:19:00
  • 段正淳的css笔记(2)圆角的做法

    2007-11-01 21:52:00
  • 使用SQL Server 2000索引视图提高性能

    2009-01-13 13:47:00
  • 微软的jQuery国际化插件

    2010-07-02 12:46:00
  • asp利用aspjpeg给图片生成PNG透明水印

    2009-03-20 14:01:00
  • ASP经常用到的函数

    2009-07-06 13:00:00
  • Google谷歌农历鼠年春节的变化

    2008-02-11 17:07:00
  • css布局自适应高度方法

    2007-05-11 17:03:00
  • YUI学习笔记(4)

    2009-03-10 18:25:00
  • SQL和Oracle对数据库事务处理的差异性

    2009-10-14 09:43:00
  • 自己用的ASP分页函数

    2009-10-18 11:30:00
  • js游戏 俄罗斯方块 源代码

    2008-01-24 13:14:00
  • 模仿PHP写的ASP分页函数

    2008-04-13 06:11:00
  • 精简版的MySQL制作步骤

    2011-03-08 09:52:00
  • Web标准学习:CSS样式书写风格

    2008-03-25 09:37:00
  • MySQL权限详解

    2011-02-16 12:20:00
  • 解决SQL Server的“此数据库没有有效所有者”问题

    2011-12-14 18:29:35
  • asp之家 网络编程 m.aspxhome.com