Simple Select with where and offset fetch clause not working in oracle

后端 未结 1 2008
南方客
南方客 2021-01-27 16:58

I am trying to select rows with where condition and will need pagination. So I have added Fetch with offset[to make it dynamic] clause but

1条回答
  •  孤街浪徒
    2021-01-27 17:26

    OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY is available from Oracle 12c.

    Instead, you need to perform your query and order the data; then generate a row number for the ordered rows; and finally filter on those row numbers. These steps need to take place in the correct order in nested sub-queries:

    SELECT *
    FROM   (
      SELECT t.*,
             ROWNUM AS rn
      FROM   (
        SELECT up.NAME AS upozilaName_bn,
               up.id AS upozila,
               dis.NAME AS districtName_bn,
               dis.id AS district,
               dv.NAME AS divisionName_bn,
               dv.id AS division,
               w.COUNTER_TYPE,
               w.COUNTER_ID,
               w.STATUS
        FROM X w
        left join  Y up ON w.UPOZILA = up.ID
        left JOIN  Z dis ON w.DISTRICT = dis.id
        left join  P dv ON w.DIVISION = dv.ID
        order by upozilaName_bn asc
      ) T
    )
    WHERE  rn BETWEEN 2 AND 11;
    

    0 讨论(0)
提交回复
热议问题