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;

  • 相关阅读:
    nfs-client-provisioner 利用NFS动态提供Kubernetes后端存储卷
    docker-compose简易编写和模板命令
    shell脚本自动过滤尝试多次连接ip并添加到系统黑名单
    Centos 升级glibc 亲测好用
    centos安装Jenkins报错
    centos8 安装docker启动失败
    cenots7 rpm 包升级ssh
    python备份文件(简易)
    Docker 容器基本操作(基础)
    Docker 环境下如何配置你的镜像(基础)
  • 原文地址:https://www.cnblogs.com/syveen/p/284362.html
Copyright © 2011-2022 走看看