国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

oracle 分頁 很棒的sql語句

2024-08-29 13:56:29
字體:
供稿:網(wǎng)友
CREATE OR REPLACE PROCEDURE PROC6338196642095312503719(輸入新聞主題 Varchar2,輸入新聞內(nèi)容 Varchar2,輸入發(fā)布時(shí)間 Varchar2,輸入當(dāng)前頁碼 Number,輸入每頁行數(shù) Number,輸出當(dāng)前頁碼 OUT Number,輸出總行行數(shù) OUT Number,輸出總頁頁數(shù) OUT Number,輸入是否下頁 Number,輸入新聞編號(hào) 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

--存儲(chǔ)過程主體
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)容||'%');

-- 輸出總頁頁數(shù)
select ceil(輸出總行行數(shù)/輸入每頁行數(shù)) into 輸出總頁頁數(shù) from dual;
exception when no_data_found then
null;
end;
-- 計(jì)算 輸入當(dāng)前頁碼 要顯示的數(shù)據(jù)總行數(shù)
if 輸入當(dāng)前頁碼 is not null then
-- xia一頁
if 輸入是否下頁 = 1 then
-- 計(jì)算 獲取數(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
-- 計(jì)算 獲取數(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 序號(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ā)布部門
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-輸入每頁行數(shù)) order by 序號(hào);
exception when no_data_found then
null;
end;

-- 輸出最后計(jì)算的當(dāng)前頁碼
if 輸入新聞編號(hào) is null and v_cPage is not null then
輸出當(dāng)前頁碼 := v_cPage;
end if;

END;
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 金平| 那曲县| 紫阳县| 衡阳县| 卢龙县| 醴陵市| 运城市| 岚皋县| 罗山县| 乐都县| 大方县| 桐城市| 饶平县| 大邑县| 尼木县| 酒泉市| 巴青县| 金川县| 平远县| 龙山县| 广宁县| 赣州市| 清原| 山丹县| 禹州市| 准格尔旗| 久治县| 尤溪县| 潮安县| 长寿区| 普宁市| 茂名市| 青川县| 罗江县| 建宁县| 宁陕县| 大同市| 肥城市| 长沙县| 项城市| 兰考县|