<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.amar.com/index.php?action=history&amp;feed=atom&amp;title=Notepad%3AOracle_Build_Custom_Aggregate_Function</id>
	<title>Notepad:Oracle Build Custom Aggregate Function - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.amar.com/index.php?action=history&amp;feed=atom&amp;title=Notepad%3AOracle_Build_Custom_Aggregate_Function"/>
	<link rel="alternate" type="text/html" href="https://wiki.amar.com/index.php?title=Notepad:Oracle_Build_Custom_Aggregate_Function&amp;action=history"/>
	<updated>2026-05-17T02:01:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.amar.com/index.php?title=Notepad:Oracle_Build_Custom_Aggregate_Function&amp;diff=285&amp;oldid=prev</id>
		<title>67.52.184.2 at 19:10, 20 February 2007</title>
		<link rel="alternate" type="text/html" href="https://wiki.amar.com/index.php?title=Notepad:Oracle_Build_Custom_Aggregate_Function&amp;diff=285&amp;oldid=prev"/>
		<updated>2007-02-20T19:10:03Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 19:10, 20 February 2007&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l95&quot;&gt;Line 95:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 95:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   END;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   END;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{{Notepad}}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wikiamar:diff:1.41:old-284:rev-285:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>67.52.184.2</name></author>
	</entry>
	<entry>
		<id>https://wiki.amar.com/index.php?title=Notepad:Oracle_Build_Custom_Aggregate_Function&amp;diff=284&amp;oldid=prev</id>
		<title>67.52.184.2: Oracle create custom Aggregate Function</title>
		<link rel="alternate" type="text/html" href="https://wiki.amar.com/index.php?title=Notepad:Oracle_Build_Custom_Aggregate_Function&amp;diff=284&amp;oldid=prev"/>
		<updated>2007-02-20T18:27:48Z</updated>

		<summary type="html">&lt;p&gt;Oracle create custom Aggregate Function&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;From : [http://www.oracle.com/technology/oramag/oracle/06-jul/o46sql.html Oracle Build Custom Aggregate Functions]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Creating the Type&lt;br /&gt;
&lt;br /&gt;
Code Listing 2: AvgInterval type specification&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TYPE AvgInterval &lt;br /&gt;
AS OBJECT (&lt;br /&gt;
&lt;br /&gt;
runningSum INTERVAL DAY(9) TO SECOND(9),&lt;br /&gt;
runningCount NUMBER,&lt;br /&gt;
&lt;br /&gt;
STATIC FUNCTION ODCIAggregateInitialize&lt;br /&gt;
  ( actx IN OUT AvgInterval&lt;br /&gt;
  ) RETURN NUMBER,&lt;br /&gt;
&lt;br /&gt;
MEMBER FUNCTION ODCIAggregateIterate&lt;br /&gt;
  ( self  IN OUT AvgInterval,&lt;br /&gt;
    val   IN       DSINTERVAL_UNCONSTRAINED&lt;br /&gt;
  ) RETURN NUMBER,&lt;br /&gt;
&lt;br /&gt;
MEMBER FUNCTION ODCIAggregateTerminate&lt;br /&gt;
  ( self             IN   AvgInterval,&lt;br /&gt;
    returnValue  OUT DSINTERVAL_UNCONSTRAINED,&lt;br /&gt;
    flags           IN   NUMBER&lt;br /&gt;
  ) RETURN NUMBER,&lt;br /&gt;
&lt;br /&gt;
MEMBER FUNCTION ODCIAggregateMerge&lt;br /&gt;
  (self  IN OUT AvgInterval,&lt;br /&gt;
   ctx2 IN      AvgInterval&lt;br /&gt;
  ) RETURN NUMBER&lt;br /&gt;
&lt;br /&gt;
);&lt;br /&gt;
/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Code Listing 3: Body of the AvgInterval type&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE OR REPLACE TYPE BODY AvgInterval AS&lt;br /&gt;
&lt;br /&gt;
STATIC FUNCTION ODCIAggregateInitialize&lt;br /&gt;
  ( actx IN OUT AvgInterval&lt;br /&gt;
  ) RETURN NUMBER IS &lt;br /&gt;
  BEGIN&lt;br /&gt;
    IF actx IS NULL THEN&lt;br /&gt;
      dbms_output.put_line(&amp;#039;NULL INIT&amp;#039;);&lt;br /&gt;
      actx := AvgInterval (INTERVAL &amp;#039;0 0:0:0.0&amp;#039; DAY TO SECOND, 0);&lt;br /&gt;
    ELSE&lt;br /&gt;
      dbms_output.put_line(&amp;#039;NON-NULL INIT&amp;#039;);&lt;br /&gt;
      actx.runningSum := INTERVAL &amp;#039;0 0:0:0.0&amp;#039; DAY TO SECOND;&lt;br /&gt;
      actx.runningCount := 0;&lt;br /&gt;
    END IF;&lt;br /&gt;
    RETURN ODCIConst.Success;&lt;br /&gt;
  END;&lt;br /&gt;
&lt;br /&gt;
MEMBER FUNCTION ODCIAggregateIterate&lt;br /&gt;
  ( self  IN OUT AvgInterval,&lt;br /&gt;
    val   IN     DSINTERVAL_UNCONSTRAINED&lt;br /&gt;
  ) RETURN NUMBER IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    DBMS_OUTPUT.PUT_LINE(&amp;#039;Iterate &amp;#039; || TO_CHAR(val));&lt;br /&gt;
    IF val IS NULL THEN &lt;br /&gt;
        /* Will never happen */&lt;br /&gt;
        DBMS_OUTPUT.PUT_LINE(&amp;#039;Null on iterate&amp;#039;);&lt;br /&gt;
    END IF;&lt;br /&gt;
    self.runningSum := self.runningSum + val;&lt;br /&gt;
    self.runningCount := self.runningCount + 1;&lt;br /&gt;
    RETURN ODCIConst.Success;&lt;br /&gt;
  END;&lt;br /&gt;
&lt;br /&gt;
MEMBER FUNCTION ODCIAggregateTerminate&lt;br /&gt;
  ( self        IN  AvgInterval,&lt;br /&gt;
    ReturnValue OUT DSINTERVAL_UNCONSTRAINED,&lt;br /&gt;
    flags       IN  NUMBER&lt;br /&gt;
  ) RETURN NUMBER IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    dbms_output.put_line(&amp;#039;Terminate &amp;#039; || to_char(flags) || to_char(self.runningsum));&lt;br /&gt;
    IF self.runningCount &amp;lt;&amp;gt; 0 THEN&lt;br /&gt;
      returnValue := self.runningSum / self.runningCount;&lt;br /&gt;
    ELSE&lt;br /&gt;
      /* It *is* possible to have an empty group, so avoid divide-by-zero. */&lt;br /&gt;
      returnValue := self.runningSum;&lt;br /&gt;
    END IF;&lt;br /&gt;
    RETURN ODCIConst.Success;&lt;br /&gt;
  END;&lt;br /&gt;
&lt;br /&gt;
MEMBER FUNCTION ODCIAggregateMerge&lt;br /&gt;
  (self IN OUT AvgInterval,&lt;br /&gt;
   ctx2 IN     AvgInterval&lt;br /&gt;
  ) RETURN NUMBER IS&lt;br /&gt;
  BEGIN&lt;br /&gt;
    self.runningSum := self.runningSum + ctx2.runningSum;&lt;br /&gt;
    self.runningCount := self.runningCount + ctx2.runningCount;&lt;br /&gt;
    RETURN ODCIConst.Success;&lt;br /&gt;
  END;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>67.52.184.2</name></author>
	</entry>
</feed>