首先獲取數據總數:
execute immediate ''Select Count(*) from (Select [id] From [table] where [Condition])'' into [iNum];
計算分頁數據上下限:
[iLow] := [iPage] * [iPageSize];
[iHigh] := [ilow] + [iPageSize];
獲取分頁數據,游標返回:
sSql := ''Select * From [table] where id between [ilow] and [ihigh]'';
open cur for sSql;
其中游標定義(在package中):
TYPE type_cur IS REF CURSOR;
函數中參數說明:out cur type_cur;
全文搜索分頁存儲過程:
/*================================================*/
/*=過程開始*/
/*================================================*/
CREATE OR REPLACE PACKAGE BODY "SEARCHTEST"."PAGE1" as
-- 返回指定分頁的數據集
PROCEDURE PageSearch(
sKey in varchar2, --搜索關鍵字
iIndex in number, --分頁頁碼
iSize in number, --頁面大小
iCount out number, --返回記錄總數
records out type_cur --返回當前頁數據記錄
)
AS
v_sql VARCHAR2(1000);
sSql varchar2(1000); --PageRecordsCount 計算記錄條目用Sql語句
ilow number;
ihei number;
sTable Varchar2(1000); --表名
sFIEld Varchar2(1000); --待搜索內容所在字段名
Begin
sTable := ''TEXT1'';
sFIEld := ''SB01'' ;
-- 按匹配程度 降序排列的 返回所有模糊數據的SQL
sSql := ''SELECT * FROM '' || sTable || '' Where Contains('' || sFIEld || '',''''About('' || sKey || '')'''' , 1) > 0 Order By Score(1) DESC'';
--取分頁總數
v_sql := ''select count(*) from ('' || sSql || '')'';
execute immediate v_sql into iCount;
--顯示任意頁內容
&
nbsp; ihei := iIndex * iSize ;
ilow := ihei - iSize + 1;
-- 對所有模糊數據 數據集 獲取列號的SQL
v_sql := ''SELECT RowNum rn , t.* From ('' || sSql || '') t'';
--獲取分頁數據
v_sql := ''select * from ('' || v_sql || '') where rn between '' || ilow || '' and '' || ihei;
open records for v_sql;
End PageSearch;
end Page1;