Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 The Oracle ORDER BY Clause      [Return To Index] Jump to:  
  Looking for the original pages? (formerly called "Morgan's Library") You can find them here.

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      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 70 users online    © 2009 psoug.org
PSOUG LOGIN
Username: 
Password: 
Forgot your password?