---- ================================================================ -- 1. 创建oracle TYPE -- ================================================================ CREATE OR REPLACE TYPE COLUMNSTRCAT as object ( str VARCHAR2(4000), static func
---- ================================================================
-- 1. 创建oracle TYPE
-- ================================================================
CREATE OR REPLACE TYPE COLUMNSTRCAT as object
(
str VARCHAR2(4000),
static function ODCIAggregateInitialize(sctx IN OUT ColumnStrCat) return number,
member function ODCIAggregateIterate(self IN OUT ColumnStrCat, value IN VARCHAR2) return number,
member function ODCIAggregateTerminate(self IN ColumnStrCat, returnValue OUT VARCHAR2, flags IN number) return number,
member function ODCIAggregateMerge(self IN OUT ColumnStrCat,ctx2 IN ColumnStrCat) return number
);
-- ================================================================
-- 2. 创建 oracle TYPE BODIES
-- ================================================================
CREATE OR REPLACE TYPE BODY COLUMNSTRCAT is
-- Member procedures and functions
static function ODCIAggregateInitialize(sctx IN OUT ColumnStrCat)
return number
is
begin
sctx := ColumnStrCat('');
return ODCIConst.Success;
end;
member function ODCIAggregateIterate(self IN OUT ColumnStrCat, value IN varchar2) return number is
counter integer;
begin
self.str := self.str||value||',';
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self IN ColumnStrCat, returnValue OUT varchar2, flags IN number) return number is
begin
returnValue := substr(self.str,1,length(self.str)-1);
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self IN OUT ColumnStrCat, ctx2 IN ColumnStrCat) return number is
begin
self.str := self.str||ctx2.str;
return ODCIConst.Success;
end;
end;
-- -- ================================================================
-- 3. 创建 oracle function
-- -- ================================================================
CREATE OR REPLACE FUNCTION COLUMNSTRJOIN (input varchar2) RETURN varchar2
PARALLEL_ENABLE AGGREGATE USING ColumnStrCat;
-- -- ================================================================
-- 4. 使用示例
-- -- ================================================================
select COLUMNSTRJOIN(a.name) from table_name a where a.type > 1