0

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

MT0
  • 143,790
  • 11
  • 59
  • 117
Nick
  • 17
  • 6

1 Answers1

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.

thatjeffsmith
  • 20,522
  • 6
  • 37
  • 120