[英]rownum issue in oracle query
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: 但是,如果我在没有ROWNUM子句的情况下运行上述查询,它将找到记录:
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. Oracle确定要返回哪些行后,需要应用ROWNUM
。 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;
Please use the thread below. 请使用下面的线程。 Pretty good explanations. 很好的解释。 https://community.oracle.com/thread/210143 Here are two working solutions. https://community.oracle.com/thread/210143这是两个可行的解决方案。
将“ and rownum <200”更改为“ WHERE rownum <200”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.