Lets you sort the records in the record stream by the values of
specific fields. You sort on a database field value expression,
called a sort key. The sort key determines the order in which
Oracle Rdb returns the records in the record stream. The default
sorting order is ascending order.
1 – Examples
The following programs demonstrate the use of the SORT clause
using the default sort order, ascending. These programs:
o Sort the records in CURRENT_INFO using SALARY as the sort key
o Sort in ascending order because no sort order is specified
o Print the last names and salaries stored in the sorted records
1.1 – C Example
#include <stdio.h>
DATABASE PERS = FILENAME "PERSONNEL";
main()
{
READY PERS;
START_TRANSACTION READ_ONLY;
FOR CI IN CURRENT_INFO
SORTED BY CI.SALARY
printf ("%s $%f\n",CI.LAST_NAME, CI.SALARY);
END_FOR;
COMMIT;
FINISH;
}
1.2 – Pascal Example
program sort_single_field (input,output);
DATABASE PERS = FILENAME 'PERSONNEL';
begin
READY PERS;
START_TRANSACTION READ_ONLY;
FOR CI IN CURRENT_INFO
SORTED BY CI.SALARY
writeln (CI.LAST_NAME, ' $', CI.SALARY :10:2);
END_FOR;
COMMIT;
FINISH;
end.
2 – Format
(B)0[msort-clause =
qqq> [4mSORTED[m [4mBY[m qqqwqwqqqqqqqqqqqqqqqqwqqqq> db-field qqqqqqwqq>
x tqq> [4mASCENDING[m qqu x
x mqq> [4mDESCENDING[m qj x
mqqqqqqqqqqqqqq , <qqqqqqqqqqqqqqqqqqqqqqj
2.1 – Format arguments
ASCENDING The default sorting order. Oracle Rdb sorts
the records in ascending order ("A"
precedes "B", 1 precedes 2, and so on).
Missing values appear as the last items
in this list of sorted values. You can
abbreviate the ASCENDING keyword to ASC.
DESCENDING Oracle Rdb sorts the records in descending
order ("A" follows "B", 1 follows 2, and
so on). Missing values appear as the first
items in this list of sorted values. You
can abbreviate the DESCENDING keyword to
DESC.
db-field A database field value expression. A
database field value expression is a field
name qualified with a context variable.
For more information see the entry on the
Database Field value expression.