oracle查询中的rownum问题 [英] rownum issue in oracle query
本文介绍了oracle查询中的rownum问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试运行此查询,但它返回零行。任何线索为什么?
从table1中选择distinct a.id
a,表b
其中.id = b.id或a.id = b.secondid)和rownum 200;但是如果我运行上面的没有ROWNUM子句的查询,它会找到记录: $ b
$ b 从table1中选择distinct a.id
a,表b
其中(a.id = b.id或a.id = b.secondid);
我困惑为什么第一个查询不工作。
< Oracle需要在之后应用 ROWNUM
Oracle确定要返回哪些行。唯一可靠的方法是: SELECT * FROM(
从table1中选择distinct a.id
a,表b
其中(a.id = b.id或a.id = b.secondid)
)WHERE ROWNUM < 200;
I m trying to run this query but it returns zero rows. Any clues why?
Select distinct a.id
from table1 a, table b
where ( a.id= b.id or a.id = b.secondid ) and rownum < 200;
But if I run the above query without the ROWNUM clause it finds records:
Select distinct a.id
from table1 a, table b
where ( a.id= b.id or a.id = b.secondid );
I'm confused why the first query is not working.
解决方案 You need to apply ROWNUM
after Oracle figures out which rows to return. The only reliable way is this:
SELECT * FROM (
Select distinct a.id
from table1 a, table b
where ( a.id= b.id or a.id = b.secondid )
) WHERE ROWNUM < 200;
这篇关于oracle查询中的rownum问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文