Oracle數(shù)據(jù)庫分頁的存儲過程
最近在復習oracle數(shù)據(jù)庫,只能說oracle數(shù)據(jù)庫實在是太強大了,當然學習起來也就復雜了。下面是使用oracle的分頁算法的存儲過程,拿出來大家參考一下吧。
我認為其中涉及到的包,游標,exception是有點難理解難記憶的,大家可以參考一下相關(guān)的書籍好好理解理解~~
//oracle分頁存儲過程 create or replace proceduce fenye(tableName in varchar2,pageSize in number,pageNow in number,myRowCount out number,myPageCount out number, p_cursor out t1.t---返回記錄數(shù)的游標 ) is --定義部分 v_sql varchar2(500); v_begin number:=(pageNow-1)*pageSize+1; v_end number:=pageNow*pageSize; begin --開始執(zhí)行部分 v_sql:='select * from (select t1.*,rownum rn from(select * from '||tableName||') t1 where rownum<='||v_end||')where rn>='||v_begin||'':這表示顯示的是第六到第十頁的數(shù)據(jù) --把游標和sql語句關(guān)聯(lián) open p_cursor for v_sql; --計算myRowCount和myPageCount v_sql:='select count(*)from '||tableName||''; execute immediate v_sql into myRowCount--執(zhí)行sql語句并把返回的值賦給myRowCount --計算myPageCount if mod(myRowCount,pageSize)=0 then myPageCount:=myRowCount/pageSize; else myPageCount:=myRowCount/pageSize+1; end if; --關(guān)閉游標 close p_cursor; end; |
posted on 2014-03-24 11:49 順其自然EVO 閱讀(243) 評論(0) 編輯 收藏 所屬分類: 數(shù)據(jù)庫