Oracle stored procedure-Paging

Source: Internet
Author: User

Create or replace package body "p_page" is
Procedure per_quickpage
(
Tbname in varchar2, -- table name
Fieldstr in varchar2, -- field set
Rowfilter in varchar2, -- filter Condition
Sortstr in varchar2, -- sorting set
Pagesize in number, -- page size
Pageindex in number, -- page number
Totalcount out number, -- total number of records
Cur_returncur out t_cursor
)
Is
V_sourcetb1 varchar2 (32000); -- Dynamic table name 1
V_sourcetb2 varchar2 (32000); -- Dynamic table name 2
V_sourcetb3 varchar2 (32000); -- Dynamic table name 3
V_sourcetb4 varchar2 (32000); -- Dynamic table name 4
V_totalcount varchar2 (50); -- total number of records
V_ SQL varchar2 (32000); -- dynamic SQL
Maxrownum number;
Minrownum number;
Begin
If (pageindex = 0) then
Minrownum: = 0;
Else
Minrownum: = (PageIndex-1) * pagesize;
End if;

Maxrownum: = minrownum + pagesize;
V_sourcetb1: = '(select' | fieldstr | 'from' | tbname | ') sourcetb1 ';
V_sourcetb2: = '(select * from' | v_sourcetb1 | 'where' | rowfilter | ''| sortstr | ') sourcetb2 ';
V_sourcetb3: = '(select rownum as rowindex, sourcetb2. * from' | v_sourcetb2 |') sourcetb3 ';
V_sourcetb4: = '(select * from' | v_sourcetb1 | 'where' | rowfilter | ') sourcetb4 ';
V_ SQL: = 'select count (*) as totalcount from '| v_sourcetb4;
Execute immediate v_ SQL into v_totalcount;
Totalcount: = v_totalcount;
V_ SQL: = 'select * from' | v_sourcetb3 | 'where rowindex> '| minrownum |' and rowindex <= '| maxrownum;
Open cur_returncur for v_ SQL;
End per_quickpage;
End p_page;

====================================
Create or replace package p_page is
Type t_cursor is ref cursor;
Procedure per_quickpage
(
Tbname in varchar2, -- table name
Fieldstr in varchar2, -- field set
Rowfilter in varchar2, -- filter Condition
Sortstr in varchar2, -- sorting set
Pagesize in number, -- page size
Pageindex in number, -- page number
Totalcount out number, -- total number of records
Cur_returncur out t_cursor
);
End p_page;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.