Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom aggregate function inside a package
    primarykey
    data
    text
    <p>I'm trying to write a custom aggregate function in Oracle and group that function inside a package together with some other functions that I have. As an example (to simulate the problem I have) suppose my custom aggregation to do a summation of numbers looks like:</p> <pre><code>CREATE OR REPLACE TYPE SUM_AGGREGATOR_TYPE AS OBJECT ( summation NUMBER, STATIC FUNCTION ODCIAggregateInitialize(agg_context IN OUT SUM_AGGREGATOR_TYPE) RETURN NUMBER, MEMBER FUNCTION ODCIAggregateIterate(self IN OUT SUM_AGGREGATOR_TYPE, next_number IN NUMBER) RETURN NUMBER, MEMBER FUNCTION ODCIAggregateMerge(self IN OUT SUM_AGGREGATOR_TYPE, para_context IN SUM_AGGREGATOR_TYPE) RETURN NUMBER, MEMBER FUNCTION ODCIAggregateTerminate(self IN SUM_AGGREGATOR_TYPE, return_value OUT NUMBER, flags IN NUMBER) RETURN NUMBER ); </code></pre> <hr> <pre><code>CREATE OR REPLACE TYPE BODY SUM_AGGREGATOR_TYPE IS STATIC FUNCTION ODCIAggregateInitialize(agg_context IN OUT SUM_AGGREGATOR_TYPE) RETURN NUMBER IS BEGIN agg_context := SUM_AGGREGATOR_TYPE(NULL); RETURN ODCIConst.Success; END; MEMBER FUNCTION ODCIAggregateIterate(self IN OUT SUM_AGGREGATOR_TYPE, next_number IN NUMBER) RETURN NUMBER IS BEGIN IF self.summation IS NULL THEN self.summation := next_number; ELSIF summation IS NOT NULL THEN self.summation := self.summation + next_number; END IF; RETURN ODCIConst.Success; END; MEMBER FUNCTION ODCIAggregateMerge(self IN OUT SUM_AGGREGATOR_TYPE, para_context IN SUM_AGGREGATOR_TYPE) RETURN NUMBER IS BEGIN self.summation := self.summation + para_context.summation; RETURN ODCIConst.Success; END; MEMBER FUNCTION ODCIAggregateTerminate(self IN SUM_AGGREGATOR_TYPE, return_value OUT NUMBER, flags IN NUMBER) RETURN NUMBER IS BEGIN return_value := self.summation; return ODCIConst.Success; END; END; </code></pre> <p>If I write the following function definition:</p> <pre><code>CREATE OR REPLACE FUNCTION MY_SUM(input NUMBER) RETURN NUMBER PARALLEL_ENABLE AGGREGATE USING SUM_AGGREGATOR_TYPE; </code></pre> <p>and corresponding type declaration to test:</p> <pre><code>CREATE OR REPLACE TYPE VECTOR IS TABLE OF NUMBER; </code></pre> <p>this statement:</p> <pre><code>select my_sum(column_value) from table(vector(1, 2, 1, 45, 22, -1)); </code></pre> <p>gives the correct result of 70. However, creating a package with the function definition:</p> <pre><code>CREATE OR REPLACE PACKAGE MY_FUNCTIONS AS FUNCTION MY_SUM(input NUMBER) RETURN NUMBER PARALLEL_ENABLE AGGREGATE USING SUM_AGGREGATOR_TYPE; END; </code></pre> <p>and calling it via:</p> <pre><code>select MY_FUNCTIONS.my_sum(column_value) from table(vector(1, 2, 1, 45, 22, -1)); </code></pre> <p>explodes with</p> <pre><code>ORA-00600: internal error code, arguments: [17090], [], [], [], [], [], [], [], [], [], [], [] </code></pre> <p>Is it possible to have custom aggregate functions nested inside package declarations?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload