oracle中只读取一条数据,怎么写

来源:百度知道 编辑:UC知道 时间:2024/05/26 12:50:15
读取第一条也好,还是读取最后一条也好,只要是给我从上万的数据中,能读取一条数据就行。
我用
top 1
不好用,不知道oracle中有什么好的函数,可以读取其中的一条数据。

select * from test where rownum=1
可以取到第一条,但你能这样用:
select * from test where rownum=2
不能说我直接取第二条。

select * from test where rownum<=5
你也可以这样用,取前5条。

rownum只能是连续的,而且必须是从1开始的

最常用的用法如下:
select * from (select rownum r ,* from test) tt
where tt.r > 0 and tt.r <= 3;

这样你就可以取任意的位置的记录了。
比如我想取第二条:
select * from (select rownum r ,* from test) tt
where tt.r = 2;

select id, num
from (select id, num, rownum xid from a2) x
where x.xid = 5

select * from table where rownum=1;--只针对rownum=1有效

查询多条时用
select * from table where rownum<=10;

这个好办啊!

自动编号是唯一的吧!

select * from 表 where 自动编号=1

呵呵!行不行啊??

望大家共同学习!