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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849create
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
12create
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