Oracle只取第一行

  1. 伪列rownum,不能用于排序和分组,除非套一层select
select col01,col02 from table1 where rownum = 1;

select col02, col02 from (select col01, col02 from table1 order by col02 ) where rownum = 1;

  1. row_number() over(),必须套一层select
select * from ( select col01,col02, row_number() over(partition by col03 order by col05 DESC) as num2 from table1 t1 ) t2 where t2.num2=1;

【Oracle只取第一行】参考资料:E11882_01/server.112/e41084/functions156.htm#i86310
  1. fetch first 版本12c才支持
select col01, col02 from table1 order by col03 fetch first 1 rows only;

  1. offset fetch next 版本12c才支持
select col02, col02 from table1 order by col03 offset 1 rows fetch next 1 rows only;

    推荐阅读