1. 程式人生 > >[筆記]Oracle、MySQL和DB2資料庫分頁查詢的實現

[筆記]Oracle、MySQL和DB2資料庫分頁查詢的實現

1.Oracle分頁查詢


SELECT * FROM (
       SELECT tt.*,ROWNUM AS rowno 
               FROM (
                    SELECT t.info_id,t.title,t.source,t.content,t.verify_time 
                            FROM CMS_INFORMATION t where t.info_id is not null
                                 ) tt   WHERE ROWNUM <= #endIndex#) 
                tab WHERE tab.rowno > #startIndex# 






2.DB2分頁查詢


SELECT * FROM (
         SELECT rownumber() over() as rc,a.* from 
            (select INFO_ID,TITLE,AUTHOR,SOURCE,SUMMARY,CONTENT,LAST_MODIFYTIME from CMS_INFORMATION order by INFO_ID desc)
as a) where rc between 

              #startIndex# and #endIndex#

3.MySQL分頁查詢(以每頁顯示10條為準)

select * from table limit (#currentPage#-1)*10,10;