Oracle-defined aggregate Functions

Source: Internet
Author: User
-- Create Function Type create type strcat_type as object (cat_string varchar2 (4000), -- set the initialization of the custom aggregate function. From here, a Aggregate Function static function odciaggresponinitialize (cs_ctx in out strcat_type) is created) return number, -- user-defined aggregate function, the main step. This function defines the specific operations of our aggregate function. In the following example, we take the maximum value, minimum value, and average value, or do the connection operation. self is the pointer to the current aggregate function, which is used to associate with the previous calculation results. member function odciaggregateiterate (self in out strcat_type, value in varchar2) return number, -- It is used to merge the results corresponding to two different pointers of two Aggregate functions. You can merge the data with different results, especially when processing parallel (parallel) queries of Aggregate functions. member function odciaggregatemerge (self in out strcat_type, ctx2 in out strcat_type) return number, -- terminate the processing of the aggregate function, and return the result of the processing of the aggregate function, returnvalue out varchar2, flags in number) return number) --/* -- function subject */create or replace type body strcat_type is static function odciaggresponinitialize (cs_ctx in out strcat_type) return number is begin cs_ctx: = strcat_type (null); Return odciconst. success; end; member function odciaggregateiterate (self in out strcat_type, value in varchar2) return number is begin self. cat_string: = self. cat_string | value; -- 2.get Union set -- If instr (self. cat_string, value) = 0 or self. cat_string is null then -- self. cat_string: = self. cat_string | ',' | value; -- else -- self. cat_string: = self. cat_string | ''; -- end if; return odciconst. success; end; member function odciaggresponterminate (self in out strcat_type, returnvalue out varchar2, flags in number) return number is begin returnvalue: = ltrim (rtrim (self. cat_string, ','), ','); Return odciconst. success; end; member function odciaggregatemerge (self in out strcat_type, ctx2 in out strcat_type) return number is begin self. cat_string: = self. cat_string | ',' | ctx2.cat _ string; return odciconst. success; end;/* function call */create or replace function strcat (input varchar2) return varchar2parallel_enable aggregate using strcat_type;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.