oracle 分頁(yè) 很棒的sql語(yǔ)句
更新時(shí)間:2009年07月01日 22:37:28 作者:
oracle 分頁(yè) 很棒的實(shí)現(xiàn)方法,大家可以分析下。
CREATE OR REPLACE PROCEDURE PROC6338196642095312503719(輸入新聞主題 Varchar2,輸入新聞內(nèi)容 Varchar2,輸入發(fā)布時(shí)間 Varchar2,輸入當(dāng)前頁(yè)碼 Number,輸入每頁(yè)行數(shù) Number,輸出當(dāng)前頁(yè)碼 OUT Number,輸出總行行數(shù) OUT Number,輸出總頁(yè)頁(yè)數(shù) OUT Number,輸入是否下頁(yè) Number,輸入新聞編號(hào) Varchar2,RETURN_CURSOR OUT CUSTOMTYPE.MYRCTYPE)
--功能描述:
--編寫(xiě)人:
--編寫(xiě)日期:
--如果返回結(jié)果集,必須使用自定義游標(biāo)Return_Cursor
IS --OR AS
--變量定義區(qū)
v_cPageCount integer; -- 要顯示的數(shù)據(jù)總行數(shù)
v_cPage integer; -- 要顯示數(shù)據(jù)的當(dāng)前頁(yè)
BEGIN
--存儲(chǔ)過(guò)程主體
if 輸入新聞編號(hào) is null then
begin
--- 輸出總行行數(shù)
select max(rownum) into 輸出總行行數(shù) from(
select * from xtnews where 1=1
and 輸入新聞主題 is null or (輸入新聞主題 is not null and V_XWZT like '%'||輸入新聞主題||'%')
and 輸入發(fā)布時(shí)間 is null or (輸入發(fā)布時(shí)間 is not null and D_FBSJ = to_date(輸入發(fā)布時(shí)間,'yyyy-mm-dd'))
)where 輸入新聞內(nèi)容 is null or (輸入新聞內(nèi)容 is not null and V_XWNR like '%'||輸入新聞內(nèi)容||'%');
-- 輸出總頁(yè)頁(yè)數(shù)
select ceil(輸出總行行數(shù)/輸入每頁(yè)行數(shù)) into 輸出總頁(yè)頁(yè)數(shù) from dual;
exception when no_data_found then
null;
end;
-- 計(jì)算 輸入當(dāng)前頁(yè)碼 要顯示的數(shù)據(jù)總行數(shù)
if 輸入當(dāng)前頁(yè)碼 is not null then
-- xia一頁(yè)
if 輸入是否下頁(yè) = 1 then
-- 計(jì)算 獲取數(shù)據(jù)的當(dāng)前頁(yè)
v_cPage := (輸入當(dāng)前頁(yè)碼 + 1);
-- 最后一頁(yè)
if v_cPage > 輸出總頁(yè)頁(yè)數(shù) then
v_cPage := 輸出總頁(yè)頁(yè)數(shù);
end if;
end if;
-- shang一頁(yè)
if 輸入是否下頁(yè) = 0 then
-- 計(jì)算 獲取數(shù)據(jù)的當(dāng)前頁(yè)
v_cPage := (輸入當(dāng)前頁(yè)碼 - 1);
-- 最前一頁(yè)
if v_cPage = 0 then
v_cPage := 1;
end if;
end if;
-- 要顯示的數(shù)據(jù)總行數(shù)
v_cPageCount := v_cPage * 輸入每頁(yè)行數(shù);
end if;
end if;
-- 執(zhí)行查詢(xún) 獲取 要顯示的數(shù)據(jù)
begin
open return_cursor for
select nts.* from(
select nt.* from (
select rownum 序號(hào),n.* from(
select * from(
select * from(
select
I_ID 新聞編號(hào),
V_XWZT 新聞主題,
V_XWNR 新聞內(nèi)容,
D_FBSJ 發(fā)布時(shí)間,
D_YXSJ 有效時(shí)間,
V_FBBM 發(fā)布部門(mén)
from xtnews
where 1=1 and 輸入新聞主題 is null or (輸入新聞主題 is not null and V_XWZT like '%'||輸入新聞主題||'%')
)where 輸入新聞內(nèi)容 is null or (輸入新聞內(nèi)容 is not null and 新聞內(nèi)容 like '%'||輸入新聞內(nèi)容||'%')
)where 輸入發(fā)布時(shí)間 is null or (輸入發(fā)布時(shí)間 is not null and 發(fā)布時(shí)間 = to_date(輸入發(fā)布時(shí)間,'yyyy-mm-dd'))
)n where 輸入新聞編號(hào) is null or (輸入新聞編號(hào) is not null and 新聞編號(hào) = 輸入新聞編號(hào))
order by rownum
)nt where nt.序號(hào) <= v_cPageCount order by 序號(hào) desc
)nts where nts.序號(hào) > (v_cPageCount-輸入每頁(yè)行數(shù)) order by 序號(hào);
exception when no_data_found then
null;
end;
-- 輸出最后計(jì)算的當(dāng)前頁(yè)碼
if 輸入新聞編號(hào) is null and v_cPage is not null then
輸出當(dāng)前頁(yè)碼 := v_cPage;
end if;
END;
--功能描述:
--編寫(xiě)人:
--編寫(xiě)日期:
--如果返回結(jié)果集,必須使用自定義游標(biāo)Return_Cursor
IS --OR AS
--變量定義區(qū)
v_cPageCount integer; -- 要顯示的數(shù)據(jù)總行數(shù)
v_cPage integer; -- 要顯示數(shù)據(jù)的當(dāng)前頁(yè)
BEGIN
--存儲(chǔ)過(guò)程主體
if 輸入新聞編號(hào) is null then
begin
--- 輸出總行行數(shù)
select max(rownum) into 輸出總行行數(shù) from(
select * from xtnews where 1=1
and 輸入新聞主題 is null or (輸入新聞主題 is not null and V_XWZT like '%'||輸入新聞主題||'%')
and 輸入發(fā)布時(shí)間 is null or (輸入發(fā)布時(shí)間 is not null and D_FBSJ = to_date(輸入發(fā)布時(shí)間,'yyyy-mm-dd'))
)where 輸入新聞內(nèi)容 is null or (輸入新聞內(nèi)容 is not null and V_XWNR like '%'||輸入新聞內(nèi)容||'%');
-- 輸出總頁(yè)頁(yè)數(shù)
select ceil(輸出總行行數(shù)/輸入每頁(yè)行數(shù)) into 輸出總頁(yè)頁(yè)數(shù) from dual;
exception when no_data_found then
null;
end;
-- 計(jì)算 輸入當(dāng)前頁(yè)碼 要顯示的數(shù)據(jù)總行數(shù)
if 輸入當(dāng)前頁(yè)碼 is not null then
-- xia一頁(yè)
if 輸入是否下頁(yè) = 1 then
-- 計(jì)算 獲取數(shù)據(jù)的當(dāng)前頁(yè)
v_cPage := (輸入當(dāng)前頁(yè)碼 + 1);
-- 最后一頁(yè)
if v_cPage > 輸出總頁(yè)頁(yè)數(shù) then
v_cPage := 輸出總頁(yè)頁(yè)數(shù);
end if;
end if;
-- shang一頁(yè)
if 輸入是否下頁(yè) = 0 then
-- 計(jì)算 獲取數(shù)據(jù)的當(dāng)前頁(yè)
v_cPage := (輸入當(dāng)前頁(yè)碼 - 1);
-- 最前一頁(yè)
if v_cPage = 0 then
v_cPage := 1;
end if;
end if;
-- 要顯示的數(shù)據(jù)總行數(shù)
v_cPageCount := v_cPage * 輸入每頁(yè)行數(shù);
end if;
end if;
-- 執(zhí)行查詢(xún) 獲取 要顯示的數(shù)據(jù)
begin
open return_cursor for
select nts.* from(
select nt.* from (
select rownum 序號(hào),n.* from(
select * from(
select * from(
select
I_ID 新聞編號(hào),
V_XWZT 新聞主題,
V_XWNR 新聞內(nèi)容,
D_FBSJ 發(fā)布時(shí)間,
D_YXSJ 有效時(shí)間,
V_FBBM 發(fā)布部門(mén)
from xtnews
where 1=1 and 輸入新聞主題 is null or (輸入新聞主題 is not null and V_XWZT like '%'||輸入新聞主題||'%')
)where 輸入新聞內(nèi)容 is null or (輸入新聞內(nèi)容 is not null and 新聞內(nèi)容 like '%'||輸入新聞內(nèi)容||'%')
)where 輸入發(fā)布時(shí)間 is null or (輸入發(fā)布時(shí)間 is not null and 發(fā)布時(shí)間 = to_date(輸入發(fā)布時(shí)間,'yyyy-mm-dd'))
)n where 輸入新聞編號(hào) is null or (輸入新聞編號(hào) is not null and 新聞編號(hào) = 輸入新聞編號(hào))
order by rownum
)nt where nt.序號(hào) <= v_cPageCount order by 序號(hào) desc
)nts where nts.序號(hào) > (v_cPageCount-輸入每頁(yè)行數(shù)) order by 序號(hào);
exception when no_data_found then
null;
end;
-- 輸出最后計(jì)算的當(dāng)前頁(yè)碼
if 輸入新聞編號(hào) is null and v_cPage is not null then
輸出當(dāng)前頁(yè)碼 := v_cPage;
end if;
END;
您可能感興趣的文章:
- oracle,mysql,SqlServer三種數(shù)據(jù)庫(kù)的分頁(yè)查詢(xún)的實(shí)例
- Oracle實(shí)現(xiàn)分頁(yè)查詢(xún)的SQL語(yǔ)法匯總
- Oracle中使用Rownum分頁(yè)詳細(xì)例子
- Oracle row_number() over()解析函數(shù)高效實(shí)現(xiàn)分頁(yè)
- 淺析Oracle和Mysql分頁(yè)的區(qū)別
- Oracle與Mysql主鍵、索引及分頁(yè)的區(qū)別小結(jié)
- Oracle、MySQL和SqlServe三種數(shù)據(jù)庫(kù)分頁(yè)查詢(xún)語(yǔ)句的區(qū)別介紹
- 分頁(yè)技術(shù)原理與實(shí)現(xiàn)之Java+Oracle代碼實(shí)現(xiàn)分頁(yè)(二)
- oracle分頁(yè)存儲(chǔ)過(guò)程 oracle存儲(chǔ)過(guò)程實(shí)例
- oracle實(shí)現(xiàn)一對(duì)多數(shù)據(jù)分頁(yè)查詢(xún)篩選示例代碼
相關(guān)文章
Oracle數(shù)據(jù)庫(kù)如何創(chuàng)建第一張表
這篇文章主要介紹了Oracle數(shù)據(jù)庫(kù)如何創(chuàng)建第一張表,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09Oracle刪除字段中的空格、回車(chē)及指定字符的實(shí)例代碼
本文給大家分享Oracle刪除字段中的空格、回車(chē)及指定字符的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下2017-03-03解決Oracle RMAN刪除歸檔日志不釋放問(wèn)題的方法
RMAN清除方式會(huì)自動(dòng)清除磁盤(pán)上的歸檔日志文件,同時(shí)會(huì)釋放控制文件中對(duì)應(yīng)的歸檔日志的歸檔信息,但最近在使用中就遇到了一個(gè)問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于解決Oracle RMAN刪除歸檔日志不釋放問(wèn)題的方法,需要的朋友可以參考下。2017-07-07oracle跨庫(kù)查詢(xún)dblink的用法實(shí)例詳解
這篇文章主要介紹了oracle跨庫(kù)查詢(xún)dblink的用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Oracle中跨庫(kù)查詢(xún)dblink的創(chuàng)建、使用及刪除等相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12oracle如何恢復(fù)被覆蓋的存儲(chǔ)過(guò)程
如果你不小心覆蓋了之前的存儲(chǔ)過(guò)程,那得趕緊閃回,時(shí)長(zhǎng)越長(zhǎng)閃回的可能性越小,下面為大家介紹下恢復(fù)原理2014-05-05oracle數(shù)據(jù)庫(kù)超全的多表查詢(xún)連接
這篇文章主要給大家介紹了關(guān)于oracle數(shù)據(jù)庫(kù)超全的多表查詢(xún)連接的相關(guān)資料,多表連接查詢(xún)實(shí)際上是通過(guò)各個(gè)表之間公共字段的關(guān)鍵性來(lái)查詢(xún)數(shù)據(jù)的,它是關(guān)系數(shù)據(jù)庫(kù)查詢(xún)的最主要的特征,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12