oracle 分页 很棒的sql语句
网络编程 2021-07-05 16:08www.168986.cn编程入门
oracle 分页 很棒的实现方法,大家可以分析下。
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;
--功能描述:
--编写人:
--编写日期:
--如果返回结果集,必须使用自定义游标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;
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程