Default row ordering for select query in oracle

2019-01-01 13:11发布

In Oracle, what is the the default ordering of rows for a select query if no "order by" clause is specified.

Is it

  1. the order in which the rows were inserted
  2. there is no default ordering at all
  3. none of the above.

8条回答
墨雨无痕
2楼-- · 2019-01-01 14:03

According to Tom Kyte: "Unless and until you add "order by" to a query, you cannot say ANYTHING about the order of the rows returned. Well, short of 'you cannot rely on the order of the rows being returned'."

See this question at asktom.com.

As for ROWNUM, it doesn't physically exist, so it can't be "freed". ROWNUM is assigned after a record is retrieved from a table, which is why "WHERE ROWNUM = 5" will always fail to select any records.

@ammoQ: you might want to read this AskTom article on GROUP BY ordering. In short:

Does a Group By clause in an Query gaurantee that the output data will be sorted on the Group By columns in order, even if there is NO Order By clause?

and we said...

ABSOLUTELY NOT,

It never has, it never did, it never will.

查看更多
骚的不知所云
3楼-- · 2019-01-01 14:05

Although, it should be rownnum (your #2), it really isn't guaranteed and you shouldn't trust it 100%.

查看更多
登录 后发表回答