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:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-12-03  
 123456
78910111213
14151617181920
21222324252627
28293031   

数据统计

  • 访问量: 6793
  • 日志数: 928
  • 影音数: 2
  • 文件数: 2
  • 书签数: 3
  • 建立时间: 2008-02-17
  • 更新时间: 2008-12-02

RSS订阅

Open Toolbar