用minus,用15条的结果集“减”5条的结果集。对于DB之查询一遍,“减法”的动作是在临时表空间里作的,不需要考虑效率。
GOOD LUCKY!
GOOD LUCKY!
解决方案 »
- Oracle启动问题
- Linux oracle监听器问题(急)
- 问下Inthirties,一个存储过程里面如何假如alter table 之类的ddl语句?
- c#.net中怎么调用oracle的fuction
- 统计如下数据的sql怎么写
- 帮忙,更改字段值
- 这个sql为什么用不上索引?
- (100分求)数据库从9i到9i2升级后一直显示ORA-01033:ORACLE initialization or shutdown in progress
- Oracle9i装不上呀!!!!急!!!
- 关于oracle缺省用户
- 在Windows2K的服务程序中连接Oracle的问题
- 捕获插入或更新的错误信息!请大家帮忙!
v_loopcounter Binary_Integer:=0;
v1 varchar2(10);
v2 varchar2(10);
cousor totalmessage is
select field1,field2 from tablename;
Begin
open totalmessage;
loop
fetch totalmessage into v1,v2;
if (v_loopcounter>=5 ) and (v_loopcounter<=10) then
dbms_output.put_line(v1||''||v2);
v_loopcounter:=v_loopcounter+1;
exit when v_loopcounter>10;
end loop
End
--------------------------------------------------------
mysql可以,但是sqlserver不可以。sqlserver:
select identity(int,1,1) #id1,* into new from tablename;
select * from new where id1 between 5 and 15;
drop table #id1;
sqlserver:
select identity(int,1,1) id1,* into #new from tablename;
select * from new where id1 between 5 and 15;
drop table #new;
minus
select * from tablename where rownum<5
这已经是最高效的方式了,
select * from tablename
...
//跳到第5条
for(int i=0;i<5;i++)
{
result.next();
}
//取10条记录
int k=0;
while(result.next()&&k<10)
{
//output result
k++;
}这种做法的效率高,还是这句
select * from (select rownum rm,a.* from table a where rownum<10) where rm>=5
的效率高呢?
呵呵,不仅仅为了面试,平时也要注意修炼啊!
然后相当于用游标fetch到相应的行上面
对于数据量大的表或查询的话,这样效率肯定不高。