In its broadest sense, learning can be defined as a process of
progressive change from ignorance to knowledge,
and from indifference to understanding....
The Same Query Returns Random Number of Rows
上一篇 /
下一篇 2007-08-04 00:00:00
/ 个人分类:Error Handle
symptom: The same query returns random number of rows
symptom: ROWNUM clause is used
symptom: DISTINCT clause is used
cause: A query with both ROWNUM and DISTINCT clauses, e.g.
select DISTINCT columns from table where ROWNUM<10;
first applies ROWNUM clause and then DISTINCT clause.
Oracle does not guarantee which rows are returned when ROWNUM clause is used:
if there are many duplicate values, DISTINCT (and the whole query) then returns
less rows than in case there are few duplicate values.
The probability of this behavior is higher with parallel processing. In this
case
rows returned by ROWNUM clause depend on which parallel processes return rows
faster at the particular run of the query.
fix:
Use an inline view to force applying DISTINCT clause first.
SQL> select columns from (select DISTINCT columns from table) where ROWNUM&
lt;10;
导入论坛
引用链接
收藏
分享给好友
推荐到圈子
管理
举报
TAG: