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

首頁 > 數據庫 > Oracle > 正文

oracle 分頁 很棒的sql語句

2020-07-26 14:34:15
字體:
來源:轉載
供稿:網友
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;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蕲春县| 铜川市| 漳浦县| 吐鲁番市| 阜城县| 松江区| 长葛市| 胶南市| 德安县| 溧阳市| 开原市| 泰来县| 科技| 乌拉特中旗| 澄城县| 曲水县| 沁阳市| 定兴县| 永昌县| 读书| 德江县| 潮安县| 子长县| 花莲市| 瑞金市| 怀安县| 天水市| 襄汾县| 深泽县| 姚安县| 福泉市| 自贡市| 安阳县| 朝阳市| 曲水县| 隆回县| 仁怀市| 阿图什市| 祁东县| 桃源县| 乌审旗|