ROWNUM IN ORACLE

后端 未结 3 1470
灰色年华
灰色年华 2021-01-29 09:24

I want to retrive record at 4th position in ORACLE 9i. Can I compare ROWNUM=4 in the WHERE clause??

3条回答
  •  佛祖请我去吃肉
    2021-01-29 10:04

    No, ROWNUM is assigned after the WHERE clause is evaluated, so it cannot "skip" rownum one to three.

    Furthermore, it is assigned BEFORE sorting.

    This is the most annoying "feature" of Oracle. They really need to implement LIMIT/OFFSET.

    You need to do something like

      select * from (
          select a.*, rownum rn from (
             select the_data from the_table order by the_order 
          ) a where rownum < 5
      ) where rn = 4
    

提交回复
热议问题