• oracle 字符串列转行


    Rows to String
    Tom Kyte's STRAGG

    This tutorial shows how to collect values from multiple rows into a single, comma delimited string. This is also known as "string aggregation". It takes values like these

    GROUP_KEY  VAL
    ---------- ----------
    Group 3    a
    Group 3    b
    Group 3    c
     and yields a string like this.

    GROUP_KEY  STRING
    ---------- ---------------
    Group 3    a,b,c

    content :------------------------------------

    create or replace type stragg_type as object
    (
      string varchar2(4000),

      static function ODCIAggregateInitialize
        ( sctx in out stragg_type )
        return number ,

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

      member function ODCIAggregateTerminate
        ( self        in  stragg_type,
          returnvalue out varchar2,
          flags in number
        ) return number ,

      member function ODCIAggregateMerge
        ( self in out stragg_type,
          ctx2 in     stragg_type
        ) return number
    );
    /

    create or replace type body stragg_type
    is

      static function ODCIAggregateInitialize
      ( sctx in out stragg_type )
      return number
      is
      begin

        sctx := stragg_type( null ) ;

        return ODCIConst.Success ;

      end;

      member function ODCIAggregateIterate
      ( self  in out stragg_type ,
        value in     varchar2
      ) return number
      is
      begin

        self.string := self.string || ',' || value ;

        return ODCIConst.Success;

      end;

      member function ODCIAggregateTerminate
      ( self        in  stragg_type ,
        returnvalue out varchar2 ,
        flags       in  number
      ) return number
      is
      begin

        returnValue := ltrim( self.string, ',' );

        return ODCIConst.Success;

      end;

      member function ODCIAggregateMerge
      ( self in out stragg_type ,
        ctx2 in     stragg_type
      ) return number
      is
      begin

        self.string := self.string || ctx2.string;

        return ODCIConst.Success;

      end;

    end;
    /

    create or replace function stragg
      ( input varchar2 )
      return varchar2
      deterministic
      parallel_enable
      aggregate using stragg_type
    ;
    /

  • 相关阅读:
    狭隘试试
    安装django
    青岛大学开源OJ以及部署
    十三、用户名密码管理
    十二、文件权限及所属主组的修改
    十一、tar打包命令的使用
    十、文件管理、属性、查找和软硬链接
    九、系统优化方法(基础优化)
    八、系统登陆信息的显示和硬件信息等
    七、常用基础配置
  • 原文地址:https://www.cnblogs.com/willsun8023/p/1590219.html
Copyright © 2020-2023  润新知