首页诗词名句在Oracle中怎样查询前10条记录?在Oracle中怎样查询前10条记录?

在Oracle中怎样查询前10条记录?


根据时间条件排序,取前十条和后十条。


【第1句】:有时间字段, 根据时间条件排序,取前十条和后十条

(1)前十条:

select * from (select * from tab_name a order by date_col )

where rownum<11;

(2)后十条:

select * from (select * from tab_name a order by date_col  desc)

where rownum<11;


【第2句】:没有时间字段, 直接根据物理存储顺序,取前十条和后十条

(1)前十条:

select * from (select * from tab_name a order by rownum) 

where rownum<11;

(2)后十条:

select * from (select * from tab_name a order by rownuml  desc) 

where rownum<11;