Oracle 9i comma partition function

Posted by catlover on Sat, 11 Apr 2020 17:40:22 +0200


1. Create type header


create or replace type string_sum_obj as object ( 
--The essence of aggregate function is an object
     sum_string varchar2(4000), 
     static function ODCIAggregateInitialize(v_self in out string_sum_obj) return number, 
-- object initialization
     member function ODCIAggregateIterate(self in out string_sum_obj, value in varchar2) return number, 
-- iterative method of aggregate function (this is the most important method)
     member function ODCIAggregateMerge(self in out string_sum_obj, v_next in string_sum_obj) return number, 
-- this method is only used when the query statement runs in parallel, which can aggregate multiple query results running in parallel
       
     member function ODCIAggregateTerminate(self in string_sum_obj, return_value out varchar2 ,v_flags in number) return number 
-- terminate the processing of the aggregate function and return the result of the processing of the aggregate function
)


2. Create type specific

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
create or replace type body string_sum_obj is 
     static function ODCIAggregateInitialize(v_self in out string_sum_obj) return number is 
     begin 
         v_self := string_sum_obj(null); 
         return ODCICONST.Success; 
     end
     member function ODCIAggregateIterate(self in out string_sum_obj, value in varchar2) return number is 
     begin 
          /* Connect, solve the problem of comma separating the first letter*/    
           if not self.sum_string is null then 
          self.sum_string := self.sum_string ||','|| value; 
          else 
          self.sum_string := self.sum_string || value; 
          end if; 
          return ODCICONST.Success; 
          /* Maximum value*/ 
          if self.sum_string<value then 
              self.sum_string:=value; 
          end if; 
          /* Minimum value*/ 
          if self.sum_string>value then 
       self.sum_string:=value;           
          end if; 
            
          return ODCICONST.Success; 
     end
     member function ODCIAggregateMerge(self in out string_sum_obj, v_next in string_sum_obj) return number is 
     begin 
          /* Connection*/    
          self.sum_string := self.sum_string || v_next.sum_string; 
          return ODCICONST.Success; 
          /* Maximum value*/ 
          if self.sum_string<v_next.sum_string then 
              self.sum_string:=v_next.sum_string; 
          end if; 
 
          /* Minimum value*/ 
          if self.sum_string>v_next.sum_string then 
              self.sum_string:=v_next.sum_string;           
          end if; 
            
          return ODCICONST.Success; 
     end
     member function ODCIAggregateTerminate(self in string_sum_obj, return_value out varchar2 ,v_flags in number) return number is 
     begin 
          return_value:= self.sum_string; 
          return ODCICONST.Success; 
     end
end;






3,Create function

1
2
create or replace function wm_concat(value Varchar2) return Varchar2 
     parallel_enable aggregate using string_sum_obj;

After creation, this is no different from the standard WM ﹣ concat. If you want to change the comma into a horizontal bar, replace it