+ User-defined aggregate functions
+
+ Some databases support user-defined aggregate functions, which can then be used along with or as . An example for such a database is Oracle. With Oracle, you can define the following OBJECT type (the example was taken from the Oracle 11g documentation):
+
+
+ SELF.MAX THEN
+ SELF.SECMAX := SELF.MAX;
+ SELF.MAX := VALUE;
+ ELSIF VALUE > SELF.SECMAX THEN
+ SELF.SECMAX := VALUE;
+ END IF;
+ RETURN ODCIConst.Success;
+END;
+
+MEMBER FUNCTION ODCIAggregateTerminate(self IN U_SECOND_MAX, returnValue OUT NUMBER, flags IN NUMBER) RETURN NUMBER IS
+BEGIN
+ RETURNVALUE := SELF.SECMAX;
+ RETURN ODCIConst.Success;
+END;
+
+MEMBER FUNCTION ODCIAggregateMerge(self IN OUT U_SECOND_MAX, ctx2 IN U_SECOND_MAX) RETURN NUMBER IS
+BEGIN
+ IF CTX2.MAX > SELF.MAX THEN
+ IF CTX2.SECMAX > SELF.SECMAX THEN
+ SELF.SECMAX := CTX2.SECMAX;
+ ELSE
+ SELF.SECMAX := SELF.MAX;
+ END IF;
+ SELF.MAX := CTX2.MAX;
+ ELSIF CTX2.MAX > SELF.SECMAX THEN
+ SELF.SECMAX := CTX2.MAX;
+ END IF;
+ RETURN ODCIConst.Success;
+END;
+END;]]>
+
+
+ The above OBJECT type is then available to function declarations as such:
+
+
+
+
+ Using the generated aggregate function
+
+ jOOQ's will detect such aggregate functions and generate them differently from regular . They implement the type, as mentioned in the manual's section about . Here's how you can use the SECOND_MAX() aggregate function with jOOQ:
+
+
+
+
+
+
+