資料庫分頁查詢,資料庫分頁

來源:互聯網
上載者:User

資料庫分頁查詢,資料庫分頁

1) mysql

select * from demowhere1=1 LIMIT 2,3

limit是用來分頁的,第一個參數是行號,第二個參數是說有多少行


2) oracle

第一種

SELECT ID, FIELD_NAME,.. .  FROM TABLE_NAME WHERE ID IN (SELECT ID                FROM (SELECT ROWNUM AS NUMROW, ID                        FROM TABLE_NAME                       WHERE 條件1                       ORDER BY 條件2)               WHERE NUMROW > 80                 AND NUMROW < 100) ORDER BY 條件3;

第二種

SELECT *  FROM   (SELECT a.*                ,rownum rn          FROM   (SELECT * FROM table_name) a          WHERE  rownum <= 40)  WHERE  rn >= 21 


如果支援scrollable result,使用ResultSet的absolute方法直接移到查詢起點,如果不支援的話,使用迴圈語句,rs.next一點點的移過去。







相關文章

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.