oracle 分頁 很棒的sql語句
更新時間:2009年07月01日 22:37:28 作者:
oracle 分頁 很棒的實現(xiàn)方法,大家可以分析下。
CREATE OR REPLACE PROCEDURE PROC6338196642095312503719(輸入新聞主題 Varchar2,輸入新聞內(nèi)容 Varchar2,輸入發(fā)布時間 Varchar2,輸入當(dāng)前頁碼 Number,輸入每頁行數(shù) Number,輸出當(dāng)前頁碼 OUT Number,輸出總行行數(shù) OUT Number,輸出總頁頁數(shù) OUT Number,輸入是否下頁 Number,輸入新聞編號 Varchar2,RETURN_CURSOR OUT CUSTOMTYPE.MYRCTYPE)
--功能描述:
--編寫人:
--編寫日期:
--如果返回結(jié)果集,必須使用自定義游標(biāo)Return_Cursor
IS --OR AS
--變量定義區(qū)
v_cPageCount integer; -- 要顯示的數(shù)據(jù)總行數(shù)
v_cPage integer; -- 要顯示數(shù)據(jù)的當(dāng)前頁
BEGIN
--存儲過程主體
if 輸入新聞編號 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ā)布時間 is null or (輸入發(fā)布時間 is not null and D_FBSJ = to_date(輸入發(fā)布時間,'yyyy-mm-dd'))
)where 輸入新聞內(nèi)容 is null or (輸入新聞內(nèi)容 is not null and V_XWNR like '%'||輸入新聞內(nèi)容||'%');
-- 輸出總頁頁數(shù)
select ceil(輸出總行行數(shù)/輸入每頁行數(shù)) into 輸出總頁頁數(shù) from dual;
exception when no_data_found then
null;
end;
-- 計算 輸入當(dāng)前頁碼 要顯示的數(shù)據(jù)總行數(shù)
if 輸入當(dāng)前頁碼 is not null then
-- xia一頁
if 輸入是否下頁 = 1 then
-- 計算 獲取數(shù)據(jù)的當(dāng)前頁
v_cPage := (輸入當(dāng)前頁碼 + 1);
-- 最后一頁
if v_cPage > 輸出總頁頁數(shù) then
v_cPage := 輸出總頁頁數(shù);
end if;
end if;
-- shang一頁
if 輸入是否下頁 = 0 then
-- 計算 獲取數(shù)據(jù)的當(dāng)前頁
v_cPage := (輸入當(dāng)前頁碼 - 1);
-- 最前一頁
if v_cPage = 0 then
v_cPage := 1;
end if;
end if;
-- 要顯示的數(shù)據(jù)總行數(shù)
v_cPageCount := v_cPage * 輸入每頁行數(shù);
end if;
end if;
-- 執(zhí)行查詢 獲取 要顯示的數(shù)據(jù)
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 新聞內(nèi)容,
D_FBSJ 發(fā)布時間,
D_YXSJ 有效時間,
V_FBBM 發(fā)布部門
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ā)布時間 is null or (輸入發(fā)布時間 is not null and 發(fā)布時間 = to_date(輸入發(fā)布時間,'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-輸入每頁行數(shù)) order by 序號;
exception when no_data_found then
null;
end;
-- 輸出最后計算的當(dāng)前頁碼
if 輸入新聞編號 is null and v_cPage is not null then
輸出當(dāng)前頁碼 := v_cPage;
end if;
END;
--功能描述:
--編寫人:
--編寫日期:
--如果返回結(jié)果集,必須使用自定義游標(biāo)Return_Cursor
IS --OR AS
--變量定義區(qū)
v_cPageCount integer; -- 要顯示的數(shù)據(jù)總行數(shù)
v_cPage integer; -- 要顯示數(shù)據(jù)的當(dāng)前頁
BEGIN
--存儲過程主體
if 輸入新聞編號 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ā)布時間 is null or (輸入發(fā)布時間 is not null and D_FBSJ = to_date(輸入發(fā)布時間,'yyyy-mm-dd'))
)where 輸入新聞內(nèi)容 is null or (輸入新聞內(nèi)容 is not null and V_XWNR like '%'||輸入新聞內(nèi)容||'%');
-- 輸出總頁頁數(shù)
select ceil(輸出總行行數(shù)/輸入每頁行數(shù)) into 輸出總頁頁數(shù) from dual;
exception when no_data_found then
null;
end;
-- 計算 輸入當(dāng)前頁碼 要顯示的數(shù)據(jù)總行數(shù)
if 輸入當(dāng)前頁碼 is not null then
-- xia一頁
if 輸入是否下頁 = 1 then
-- 計算 獲取數(shù)據(jù)的當(dāng)前頁
v_cPage := (輸入當(dāng)前頁碼 + 1);
-- 最后一頁
if v_cPage > 輸出總頁頁數(shù) then
v_cPage := 輸出總頁頁數(shù);
end if;
end if;
-- shang一頁
if 輸入是否下頁 = 0 then
-- 計算 獲取數(shù)據(jù)的當(dāng)前頁
v_cPage := (輸入當(dāng)前頁碼 - 1);
-- 最前一頁
if v_cPage = 0 then
v_cPage := 1;
end if;
end if;
-- 要顯示的數(shù)據(jù)總行數(shù)
v_cPageCount := v_cPage * 輸入每頁行數(shù);
end if;
end if;
-- 執(zhí)行查詢 獲取 要顯示的數(shù)據(jù)
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 新聞內(nèi)容,
D_FBSJ 發(fā)布時間,
D_YXSJ 有效時間,
V_FBBM 發(fā)布部門
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ā)布時間 is null or (輸入發(fā)布時間 is not null and 發(fā)布時間 = to_date(輸入發(fā)布時間,'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-輸入每頁行數(shù)) order by 序號;
exception when no_data_found then
null;
end;
-- 輸出最后計算的當(dāng)前頁碼
if 輸入新聞編號 is null and v_cPage is not null then
輸出當(dāng)前頁碼 := v_cPage;
end if;
END;
您可能感興趣的文章:
- oracle,mysql,SqlServer三種數(shù)據(jù)庫的分頁查詢的實例
- Oracle實現(xiàn)分頁查詢的SQL語法匯總
- Oracle中使用Rownum分頁詳細(xì)例子
- Oracle row_number() over()解析函數(shù)高效實現(xiàn)分頁
- 淺析Oracle和Mysql分頁的區(qū)別
- Oracle與Mysql主鍵、索引及分頁的區(qū)別小結(jié)
- Oracle、MySQL和SqlServe三種數(shù)據(jù)庫分頁查詢語句的區(qū)別介紹
- 分頁技術(shù)原理與實現(xiàn)之Java+Oracle代碼實現(xiàn)分頁(二)
- oracle分頁存儲過程 oracle存儲過程實例
- oracle實現(xiàn)一對多數(shù)據(jù)分頁查詢篩選示例代碼
相關(guān)文章
一文解決ORA-01034:?ORACLE?not?available報錯
這篇文章主要給大家介紹了關(guān)于ORA-01034:?ORACLE?not?available報錯解決的相關(guān)資料,這是oracle數(shù)據(jù)庫啟動經(jīng)常會遇到的問題,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2024-03-03
oracle 存儲過程返回 結(jié)果集 table形式的案例
這篇文章主要介紹了oracle 存儲過程返回 結(jié)果集 table形式的案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-01-01
oracle 聲明游標(biāo)(不具備字段)規(guī)則應(yīng)用
在開發(fā)過程中可能會聲明一個含有某張表不具備字段的游標(biāo),來解決特殊問題,本文將詳細(xì)介紹這類問題,需要了解更多的朋友可以參考下2012-11-11
Oracle如何設(shè)置表空間數(shù)據(jù)文件大小
這篇文章主要介紹了Oracle如何設(shè)置表空間數(shù)據(jù)文件大小,文中講解非常細(xì)致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
Oracle?數(shù)據(jù)庫中的全文搜索整體流程分析
Oracle 是一種功能強大的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),它提供了各種功能來處理和管理大量的數(shù)據(jù),這篇文章主要介紹了Oracle?數(shù)據(jù)庫中的全文搜索功能,需要的朋友可以參考下2024-04-04

