日期:2014-05-17 浏览次数:20977 次
CREATE OR REPLACE PROCEDURE DivPageBySql
(
pstrSql in varchar2,
pnPageSize in NUMERIC,
pnPageIndex in NUMERIC,
pnRowCount out NUMERIC
)
IS
v_pfrist number;
v_sql varchar2(4000);
v_notecount number;
v_min number;
v_max number;
v_sql1 varchar2(100);
v_sql2 varchar2(100);
v_sql3 varchar2(4000);
BEGIN
--查询总记录的SQL
v_sql:='select count(*) from (' || pstrSql || ')';
--执行SQL把总记录结果得到
execute immediate v_sql into v_notecount;
--求出总页数
pnRowCount := ceil(v_notecount/pnPageSize);
-- 如果传进来的页数大于最后一页,默认返回最后一页数据
v_pfrist := pnPageIndex;
IF(v_pfrist > pnRowCount)THEN
v_pfrist := pnRowCount;
end IF;
--显示页的最大记录排行值
v_max := v_pfrist * pnPageSize;
--显示页的最小记录排行值
v_min := v_max - pnPageSize +1;
--分页SQL
v_sql1 := 'select * from (select rownum rn,t.* from ';
v_sql2 := ' t ) where rn between '||v_min||' and '||v_max;
v_sql3 := v_sql1||' ( '||pstrSql||' ) '||v_sql2;
execute immediate v_sql3;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
END DivPageBySql;
Database.AddInParameter(command, "pstrSql", DbType.String, strSqlCmd);
Database.AddInParameter(command, "pnPageSize", DbType.Int32, pageSize);
Database.AddInParameter(command, "pnPageIndex", DbType.Int32, pageIndex);
Database.AddOutParameter(command, "pnRowCount", DbType.Int32, sizeof(int));
DataSet ds;
ds = Database.ExecuteDataSet(command);