Pagination custom query fetch first N rows error [duplicate]

瘦欲@ 提交于 2021-02-11 13:41:33

问题


I have such a long query like this in Oracle 10g (needed for custom pagination).

SELECT *
  FROM (
       SELECT FILTERED_ORDERED_RESULTS.*,
              COUNT(1) OVER() TOTAL_RECORDS
         FROM (
              SELECT BASEINFO.*,
                     ROWNUM AS RN
                FROM (
                     SELECT A.ID_LIST            AS ID,
                            A.NAME,
                            A.DATE_CREATE        AS DATECREATE,
                            A.DATE_UPDATE        AS DATEUPDATE,
                            A.USER_ID            AS USERID,
                            A.TYPE,
                            NVL(
                                   B.CNT, 0
                            )        CNT
                       FROM MAP_S_LIST_ARTS                                                           A
                       LEFT JOIN (
                            SELECT ID_LIST,
                                   COUNT(*) CNT
                              FROM MAP_LIST_ARTS
                             GROUP BY ID_LIST
                     )        B ON A.ID_LIST = B.ID_LIST
                      ORDER BY A.ID_LIST DESC
              ) BASEINFO
       ) FILTERED_ORDERED_RESULTS
        ORDER BY CNT DESC
)
 WHERE RN > (:PAGE * 5) AND RN <= (:PAGE + 1) * 5 

Now I have this behavior... I don't get the correct ordering throughout all the data, only inside the rn range specified and for some reason rn doesn't want to change... So i get onluy chunks of filtering


回答1:


FETCH FIRST N ROWS is a new SQL syntax supported in Oracle 12c and higher. Oracle 10g (what you tagged) does not support this, you would have to use something like

WHERE ROWNUM < 6

Please update your question with exact version of Oracle Database and the actual error message so we can know for sure what your issue is.



来源:https://stackoverflow.com/questions/60709028/pagination-custom-query-fetch-first-n-rows-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!