类似与WMSYS.WM_CONCAT函数的方法
CREATE OR REPLACE TYPE STR_SUM_OBJ AS OBJECT --聚合函数的实质就是一个对象
(
SUM_STRING VARCHAR2(4000),
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(V_SELF IN OUT STR_SUM_OBJ)
RETURN NUMBER, --对象初始化
--聚合函数的迭代方法(这是最重要的方法)
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT STR_SUM_OBJ,
VALUE IN VARCHAR2) RETURN NUMBER,
--当查询语句并行运行时,才会使用该方法,可将多个并行运行的查询结果聚合
MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT STR_SUM_OBJ,
V_NEXT IN STR_SUM_OBJ)
RETURN NUMBER,
--终止聚集函数的处理,返回聚集函数处理的结果.
MEMBER FUNCTION ODCIAGGREGATETERMINATE(SELF IN STR_SUM_OBJ,
RETURN_VALUE OUT VARCHAR2,
V_FLAGS IN NUMBER)
RETURN NUMBER
)
/
CREATE OR REPLACE FUNCTION STR_SUM(VALUE VARCHAR2) RETURN VARCHAR2
PARALLEL_ENABLE AGGREGATE USING STR_SUM_OBJ;
/
CREATE OR REPLACE TYPE BODY STR_SUM_OBJ IS
STATIC FUNCTION ODCIAGGREGATEINITIALIZE(V_SELF IN OUT STR_SUM_OBJ)
RETURN NUMBER IS
BEGIN
V_SELF := STR_SUM_OBJ(NULL);
RETURN ODCICONST.SUCCESS;
END;
MEMBER FUNCTION ODCIAGGREGATEITERATE(SELF IN OUT STR_SUM_OBJ,
VALUE IN VARCHAR2) RETURN NUMBER IS
BEGIN
SELF.SUM_STRING := SELF.SUM_STRING || VALUE;
RETURN ODCICONST.SUCCESS;
END ODCIAGGREGATEITERATE;
MEMBER FUNCTION ODCIAGGREGATEMERGE(SELF IN OUT STR_SUM_OBJ,
V_NEXT IN STR_SUM_OBJ)
RETURN NUMBER IS
BEGIN
SELF.SUM_STRING := SELF.SUM_STRING || V_NEXT.SUM_STRING;
RETURN ODCICONST.SUCCESS;
&nbs