ORACLE自定义聚合函数

create or replace type obj_bitor as object ( 

v_obj_bitor number, 

static function ODCIAggregateInitialize(v_self in out obj_bitor ) return number, 

member function ODCIAggregateIterate(self in out obj_bitor, value in number) return number, 

member function ODCIAggregateMerge(self in out obj_bitor, v_next in obj_bitor) return number, 

member function ODCIAggregateTerminate(self in obj_bitor, return_value out number ,v_flags in number) return number 

)


//2.实现对象

create or replace type body obj_bitor is 

static function ODCIAggregateInitialize(v_self in out obj_bitor) return number is 

begin 

v_self := obj_bitor(null); 

return ODCICONST.Success; 

end; 


member function ODCIAggregateIterate(self in out obj_bitor , value in number) return number is 

begin 

if self.v_obj_bitor is null then 

self.v_obj_bitor := value; 

else 

self.v_obj_bitor := self.v_obj_bitor + value - bitand(self.v_obj_bitor, value); 

end if; 

return ODCICONST.Success; 

end; 


member function ODCIAggregateMerge(self in out obj_bitor, v_next in obj_bitor) return number is 

begin 

if self.v_obj_bitor is null then 

self.v_obj_bitor := nvl(v_next.v_obj_bitor, null); 

else 

if v_next.v_obj_bitor is not null then 

self.v_obj_bitor := self.v_obj_bitor + v_next.v_obj_bitor - bitand(self.v_obj_bitor, v_next.v_obj_bitor); 

end if; 

end if; 

return ODCICONST.Success; 

end; 


member function ODCIAggregateTerminate(self in obj_bitor, return_value out number,v_flags in number) return number is 

begin 

return_value := self.v_obj_bitor; 

return ODCICONST.Success; 

end; 

end; 


//3.定义聚合函数

create or replace function bit_or(value number) return number 

parallel_enable aggregate using obj_bitor; 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/11269.html