Oracle SQL returns rows in arbitrary fashion when no "order by" clause is used Oracle SQL returns rows in arbitrary fashion when no "order by" clause is used oracle oracle

Oracle SQL returns rows in arbitrary fashion when no "order by" clause is used


The order of rows returned to the application from a SELECT statement is COMPLETELY ARBITRARY unless otherwise specified. If you want, need, or expect rows to return in a certain order, it is the user's responsibility to specify such an order.

(Caveat: Some versions of Oracle would implicitly sort data in ascending order if certain operations were used, such as DISTINCT, UNION, MINUS, INTERSECT, or GROUP BY. However, as Oracle has implemented hash sorting, the nature of the sort of the data can vary, and lots of SQL relying on that feature broke.)


There is no default ordering, ever. If you don't specify ORDER BY, you can get the same result the first 10000 times, then it can change.

Note that this is also true even with ORDER BY for equal values. For example:

Col1 Col21    12    13    24    2

If you use ORDER BY Col2, you still don't know if row 1 or 2 will come first.


Just image the rows in a table like balls in a basket. Do the balls have an order?

I dont't think there is any DBMS that guarantees an order if ORDER BY is not specified.

Some might always return the rows in the order they were inserted, but that is an implementation side effect.

Some execution plans might cause the result set to be ordered even without an ORDER BY, but again this is an implementation side-effect that you should not rely on.