Quick Search:
 
 The Oracle ORDER BY Clause      [Return To Index] Jump to:  

Term: ORDER BY

Definition:
The Oracle ORDER BY clause specifies the sorting, or order, that rows are returned in from a query.

The ORDER BY clause always uses a parameter that tells the database how to sort the returned rows. Valid parameters are ASC or DESC. These specify ascending order and descending order.

  • The ASC parameter
  • The DESC parameter

Random Ordering
To order rows randomly, you must use DBMS_RANDOM, as shown here:

SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 5


In the example above, 5 randomly selected rows will be returned.

You can also get a random sample, by using the SAMPLE clause with a SELECT statement:

SELECT * FROM users SAMPLE(15);


In the example above, Oracle is instructed to randomly return 15% of the rows in the 'users' table. Note that the SAMPLE clause only works for single table queries on local tables.


Related Links:

Related Code Snippets:
  • ORDER BY Clause - The ORDER BY clause is used by, and is the last clause of, a SELECT statement.
 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org