How to call the Oracle paging stored procedure in ibatis

Source: Internet
Author: User

Do you feel a headache when ibatis calls the Oracle paging stored procedure? If this is the case, the following articles will provide you with corresponding solutions. The following articles mainly introduce the operation solution for ibatis to call the Oracle paging stored procedure, the following is a detailed description of the relevant content.

Oracle paging:

 
 
  1. create or replace procedure P_QuerySplit( 

Sqlscript varchar2, table name/SQL statement

PageSize integer, number of records per page

PageIndex integer, current page

TotalCount out number, total number of records

TotalPage out number, total number of pages

V_cur out sys_refcursor returns the cursor

 
 
  1. ) is  
  2. /**  
  3. * by chenjianxin 2008-5-3  
  4. *  
  5. */  
  6. v_PageSize number;  
  7. v_PageIndex number;  
  8. v_SQL_Count varchar2(4000);  
  9. v_SQL varchar2(4000);  
  10. v_StartIndex number;  
  11. v_EndIndex number;  
  12. begin  
  13. v_PageSize:=pageSize;  
  14. if v_PageSize=0 then  
  15. v_PageSize:=1;  
  16. end if;  

Count records

 
 
  1. v_SQL_Count := 'select count(*) from (' ? ? sqlscript ? ?') a ';  
  2. execute immediate v_SQL_Count into totalCount;  

Total number of pages

 
 
  1. totalPage:=CEIL(totalCount/v_PageSize); 

Verify the page number. If the page number is larger than the maximum number of pages, return to the last page.

 
 
  1. v_PageIndex:=pageIndex;  
  2. if v_PageIndex>totalPage then  
  3. v_PageIndex:=totalPage;  
  4. end if;  

Calculate the start Index and end Index

 
 
  1. v_StartIndex:=(v_PageIndex-1)*v_PageSize 1;  
  2. v_EndIndex:=v_PageIndex*v_PageSize;  
  3. v_SQL:='SELECT /* FIRST_ROWS */* FROM (';  
  4. v_SQLv_SQL:=v_SQL ? ?' SELECT A.*, ROWNUM RN ';  
  5. v_SQLv_SQL:=v_SQL ? ?' FROM (' ? ?sqlscript ? ?') A ';  
  6. v_SQLv_SQL:=v_SQL ? ?' WHERE ROWNUM <= ' ? ?v_EndIndex;  
  7. v_SQLv_SQL:=v_SQL ? ?')WHERE RN >= ' ? ?v_StartIndex;  
  8. open v_cur for v_SQL;  
  9. end P_QuerySplit;   

The above content describes the calling of the Oracle paging stored procedure by ibatis, hoping to help you in this regard.

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.