After a query is defined with the aforementioned query elements, the result is a set of items. The ORDER BY directive orders the results by item properties. For example:

age > 30 ORDER BY firstName

This query returns a result set where items are ordered by the firstName property in ascending order—the default. Results can also be ordered in descending order by adding SORT DESC to the end of the directive:

age > 30 ORDER BY firstName SORT DESC

Results can be ordered by multiple properties. For example:

age > 30 ORDER BY lastName, firstName SORT DESC

This orders results by lastName. If multiple results have the same lastName, within their group they are ordered by firstName in descending order.

A further directive, CASE IGNORECASE, can specify case-insensitive sorting:

age > 30 ORDER BY firstName SORT DESC CASE IGNORECASE

Note that you can omit the tokens SORT and CASE, unless you use parameters for the ASC/DESC or USECASE/IGNORECASE tokens.


Copyright © 1997, 2015 Oracle and/or its affiliates. All rights reserved. Legal Notices