日期:2014-05-20  浏览次数:20481 次

谁能提供一个高效的ORACLE分页SQL语句啊,谢谢了
如题!

------解决方案--------------------
string sql = string.Format(
@ "
select * from
(select t.*,rownum as row_num from
(select * from b_Brand where 1 = 1 {0} order by {1} {2}) t
) t1
where t1.row_num between {3} * {4} + 1 and ({3} + 1) * {4}
"
,
sb.ToString(),
sortExpress,
sortDirection,
pageIndex,
pageSize);
------解决方案--------------------
create or replace procedure KnowledgePagerCount(p_PageSize number, --每页记录数
p_PageNo number, --当前页码,从 1 开始
p_SqlSelect varchar2, --查询语句,含排序部分
p_OutRecordCount out number,--返回总记录数
cur_OUT out GM.PAGER.refCursorType)
as
v_sql varchar2(3000);
v_count number;
v_heiRownum number;
v_lowRownum number;
begin
----取记录总数
execute immediate p_SqlSelect into v_count;
p_OutRecordCount := v_count;
----执行分页查询
v_heiRownum := p_PageNo * p_PageSize;
v_lowRownum := v_heiRownum - p_PageSize + 1;

v_sql := 'SELECT *
FROM (
SELECT A.*, rownum rn
FROM ( '|| p_SqlSelect || ') A
WHERE rownum <= '|| to_char(v_heiRownum) || '
) B
WHERE rn > = ' || to_char(v_lowRownum) ;
--注意对rownum别名的使用,第一次直接用rownum,第二次一定要用别名rn

OPEN cur_OUT FOR v_sql;

end KnowledgePagerCount;

给你个存储过程