22 User-Defined Aggregate Functions Interface
These routines must be implemented to define a user-defined aggregate function. The routines are implemented as methods in an object type. Then the CREATE FUNCTION
statement is used to actually create the aggregate function.
See Also:
22.1 User-Defined Aggregate Functions
The methods described here are implemented as methods in an object type. The CREATE FUNCTION
statement is used to actually create the aggregate function. Table 22-1 summarizes these functions.
Table 22-1 Summary of User-Defined Aggregate Functions
Function | Description |
---|---|
Removes an input value from the current group. |
|
Initializes the aggregation context and instance of the implementation object type, and returns it as an |
|
Iterates through input rows by processing the input values, updating and then returning the aggregation context. Note : ODCIAggregateIterate is not invoked for null values. |
|
Merges two aggregation contexts into a single object instance during either serial or parallel evaluation of the user-defined aggregate. |
|
Calculates the result of the aggregate computation and performs all necessary cleanup, such as freeing memory. |
|
Integrates all external pieces of the current aggregation context to make the context self-contained. |
22.1.1 ODCIAggregateDelete()
Removes an input value from the current group. The routine is invoked by Oracle by passing in the aggregation context and the value of the input to be removed during It processes the input value, updates the aggregation context, and returns the context. This is an optional routine and is implemented as a member method.
Syntax
MEMBER FUNCTION ODCIAggregateDelete( self IN OUT <impltype>, val <inputdatatype>) RETURN NUMBER
Parameter | IN/OUT | Description |
---|---|---|
self |
IN OUT |
As input, the value of the current aggregation context; as output, the updated value. |
val |
IN |
The input value that is being removed from the current group. |
Returns
ODCIConst.Success
on success, or ODCIConst.Error
on error.
22.1.2 ODCIAggregateInitialize()
Initializes the aggregation context and instance of the implementation object type, and returns it as an OUT
parameter. Implement this routine as a static method.
Syntax
STATIC FUNCTION ODCIAggregateInitialize( actx IN OUT <impltype>) RETURN NUMBER
Parameter | In/Out | Description |
---|---|---|
actx |
IN OUT |
The aggregation context that is initialized by the routine. This value is |
Returns
ODCIConst.Success
on success, or ODCIConst.Error
on error.
22.1.3 ODCIAggregateIterate()
Iterates through input rows by processing the input values, updating and then returning the aggregation context. This is a mandatory routine and is implemented as a member method.
Syntax
MEMBER FUNCTION ODCIAggregateIterate( self IN OUT <impltype>, val <inputdatatype>) RETURN NUMBER
Parameter | IN/OUT | Description |
---|---|---|
self |
IN OUT |
As input, the value of the current aggregation context; as output, the updated value. |
val |
IN |
The input value that is being aggregated. |
Returns
ODCIConst.Success
on success, or ODCIConst.Error
on error.
22.1.4 ODCIAggregateMerge()
Merges two aggregation contexts into a single object instance during either serial or parallel evaluation of the user-defined aggregate. This is a mandatory routine and is implemented as a member method.
Syntax
MEMBER FUNCTION ODCIAggregateMerge( self IN OUT <impltype>, ctx2 IN <impltype>) RETURN NUMBER
Parameter | IN/OUT | Description |
---|---|---|
self |
IN OUT |
On input, the value of the first aggregation context; on output, the resulting value of the two merged aggregation contexts. |
ctx2 |
IN |
The value of the second aggregation context. |
Returns
ODCIConst.Success
on success, or ODCIConst.Error
on error.
If the user-defined aggregate is a window function, and it is not possible to make an implementation of ODCIAggregateMerge(), ODCIConst.Error
should be returned. This error is translated as an Oracle user error.
22.1.5 ODCIAggregateTerminate()
Calculates the result of the aggregate computation and performs all necessary cleanup, such as freeing memory. Invoked by Oracle as the last step of aggregate computation. This is a mandatory routine and is implemented as a member method.
Syntax
MEMBER FUNCTION ODCIAggregateTerminate( self IN <impltype>, ReturnValue OUT <return_type>, flags IN number) RETURN NUMBER
Parameter | IN/OUT | Description |
---|---|---|
self |
IN |
The value of the aggregation context. |
ctx2 |
OUT |
The resultant aggregation value. |
flags |
IN |
A bit vector that indicates various options. A set bit of |
Returns
ODCIConst.Success
on success, or ODCIConst.Error
on error.
See Also:
"Reuse of Aggregation Context for Analytic Functions" for details on setting the ODCI_AGGREGATE_REUSE_CTX
flag bit.
22.1.6 ODCIAggregateWrapContext()
Integrates all external pieces of the current aggregation context to make the context self-contained. Invoked by Oracle if the user-defined aggregate has been declared to have external context and is transmitting partial aggregates from slave processes. This is an optional routine and is implemented as a member method.
Syntax
MEMBER FUNCTION ODCIAggregateWrapContext( self IN OUT <impltype>) RETURN NUMBER
Parameter | IN/OUT | Description |
---|---|---|
self |
IN |
On input, the value of the current aggregation context; on output, the self-contained combined aggregation context. |
Returns
ODCIConst.Success
on success, or ODCIConst.Error
on error.
See Also:
"Handling Large Aggregation Contexts" for more information on using this function