求一个能用的Oracle分页存储过程?
Oracle库里有上万条数据,.NET自带的分页功能效率太低了,想用数据存储过程以提高效率,要求存储过程带where查询条件且是动态查询
------解决方案--------------------select *
from (select rownum rw, fields from table where <condition>)
where rw <= <end row>
and rw > <end row>
------解决方案--------------------此函数原创作人为:oracledbalgtu ,特此声明!!
分页一般语法如下:
CREATE OR REPLACE FUNCTION GG(S INT, E INT) RETURN SYS_REFCURSOR AS
R_C SYS_REFCURSOR;
BEGIN
OPEN R_C FOR 'SELECT ename,empno
FROM SCOTT.EMP
WHERE ROWID IN (SELECT RID
FROM (SELECT ROWNUM RNO, ROWID RID
FROM (SELECT ROWID
FROM SCOTT.EMP
ORDER BY ENAME)
WHERE ROWNUM <= :E)
WHERE RNO >= :S)'
USING E, S;
RETURN R_C;
END;
/
DECLARE
r_c SYS_REFCURSOR;
v_c1 VARCHAR2(10);
v_c2 VARCHAR2(10);
BEGIN
r_c:=gg(2,6);
LOOP
FETCH r_c INTO v_c1,v_c2;
EXIT WHEN r_c%NOTFOUND;
dbms_output.put_Line(v_c1
------解决方案--------------------
'-'
------解决方案--------------------
v_c2);
END LOOP;
CLOSE r_c;
END;
/
------解决方案--------------------能分页的SQL语句也行,存储过程写起来还有点麻烦 解决了 再加分 ,原来程序中的SQL语句:
select orderhist.orderid ,orderhist.mailid,orderhist.senddt,contact.contactid, contact.name, Fun_GetCityName(orderhist.spellid), Fun_GetAddress(contact.contactid), orderhist.crusr,orderhist.result,orderhist.status,orderhist.crdt, orderhist.mailtype,orderhist.paytype,orderhist.status, orderhist.totalprice from orderhist inner join contact on orderhist.contactid=contact.contactid where 1=1
orderhist(订单表) contact(联系人表)
------解决方案--------------------学习
------解决方案--------------------期待更多的解答,解决了在加分....
------解决方案--------------------