next up previous contents
Next: Online Version Up: SQL-AG System Previous: Compiling a New

User-Defined Aggregates in SQL-AG Queries

As described in chapter 2 the aggregate can be used as:

The first one above is an aggregate calculation without any group-by fields, and second one is aggregate calculation with group-by.

The user can specify the first one in the following way for the created stored PL/SQL procedure:

Here depending on the OutputTable, if 'STDOUT' then the output is dumped on the screen, else the OutputTable is created and the output is inserted into that table. Also the user can shorten the above procedure in case the OutputTable is 'STDOUT' and write as:

(This is because GroupFields and OutputTable has default values as 'NULL' and 'STDOUT').

WhereClause contains the condition for the where clause, for which it accepts any expression or 'EMPTY. If this is 'EMPTY', the above command can be further reduced to:

For the second template above there are two ways the user can compute the aggregate. The user either can pre-sort the table (by using the order-by statement of SQL for fetching the records of the InputTable) and compute the aggregate. Or the table is fetched in the existing order, storing for each group-by value internally. User can specify either ways in the following manner:

(Note: Non order-by is the default way.)

The above ways are the defined ways the user is suppose to use the aggregate. All the calls are legal calls in any PL/SQL code. For just making calls to aggregates :

would suffice.



Punit Bhargava
Wed Mar 11 18:50:53 PST 1998