zoukankan      html  css  js  c++  java
  • [收藏]在oracle里定义一个自定义字符串的聚集函数

    create or replace type strcat_type as object (
        cat_string varchar2(4000),
        static function ODCIAggregateInitialize(cs_ctx In Out strcat_type) return number,
        member function ODCIAggregateIterate(self In Out strcat_type,value in varchar2) return number,
        member function ODCIAggregateMerge(self In Out strcat_type,ctx2 In Out strcat_type) return number,
        member function ODCIAggregateTerminate(self In Out strcat_type,returnValue Out varchar2,flags in number) return number
    )

    --------------

    create or replace type body strcat_type is
      static function ODCIAggregateInitialize(cs_ctx IN OUT strcat_type) return number
      is
      begin
          cs_ctx := strcat_type( null );
          return ODCIConst.Success;
      end;

      member function ODCIAggregateIterate(self IN OUT strcat_type,
                                           value IN varchar2 )
      return number
      is
      begin
          --1. concat string
          self.cat_string := self.cat_string || ','|| value;
          -- 2.get union set
          -- if  instr(self.cat_string, value ) = 0 or self.cat_string is null then
          --        self.cat_string := self.cat_string || ',' || value ;
          -- else
          --        self.cat_string := self.cat_string ||'' ;
          -- end if ;
          return ODCIConst.Success;
      end;

      member function ODCIAggregateTerminate(self IN Out strcat_type,
                                             returnValue OUT varchar2,
                                             flags IN number)
      return number
      is
      begin
          returnValue := ltrim(rtrim(self.cat_string,','),',');
          return ODCIConst.Success;
      end;

      member function ODCIAggregateMerge(self IN OUT strcat_type,
                                         ctx2 IN Out strcat_type)
      return number
      is
      begin
          self.cat_string := self.cat_string || ',' || ctx2.cat_string;
          return ODCIConst.Success;
      end;

    end;

    -------------------

    CREATE OR REPLACE FUNCTION strcat(input varchar2 )
    RETURN varchar2
    PARALLEL_ENABLE AGGREGATE USING strcat_type;

  • 相关阅读:
    使用ClassLoader加载配置文件
    Io流和Properties集合的联合应用
    文件拷贝案例
    倒计时
    静态代码块
    数组的四种排序(冒泡排序,选择排序,插入排序,快速排序)
    通过map集合统计每个字符出现的次数
    随机输入几个数字,删除重复数字(但要保留一个),留下不重复的数字
    流程图学习-1-基础符号
    Java-List的对象的校验不起作用的解决方案
  • 原文地址:https://www.cnblogs.com/syveen/p/284362.html
Copyright © 2011-2022 走看看