·¢²©ÎÄ
Blue_Stone's OpenWorld

http://blog.chinaunix.net/space.php?uid=7761148

When You Learn,Teach, When You Get,Give.   
¸öÈË×ÊÁÏ
  • ²©¿Í·ÃÎÊ£º1312033
  • ²©ÎÄÊýÁ¿£º418
  • ²©¿Í»ý·Ö£º10213
  • ²©¿ÍµÈ¼¶£ºÉϽ«
  • ¹Ø×¢ÈËÆø£º 1
  • ×¢²áʱ¼ä£º2005-06-09 18:02:52
¶©ÔÄÎҵIJ©¿Í
  • ¶©ÔÄ
  • ¶©Ôĵ½Ïʹû
  • ¶©Ôĵ½×¥Ïº
  • ¶©Ôĵ½Google
×ÖÌå´óС£º´ó ÖРС²©ÎÄ
·ÖÀࣺ Oracle¼¼ÇÉ

ǰ¼¸ÌìÔÚcuÉÏ¿´µ½Ñ°Çó½«×Ö·û´®Á¬½ÓÆðÀ´µÄ·½·¨, Ïëµ½ÓÃÒ»¸öÀàËÆsumµÈ¾ÛºÏº¯ÊýµÄº¯Êý¿ÉÒÔ¸ü¼òµ¥µÄʵÏÖ, ËÑË÷ÁËÒ»ÏÂoracle 10gµÄÎĵ², ÕÒµ½¸öʾÀý, ¾ÍÒÀºù«»­Æ°µÄдÁËÒ»¸ö. ÔÚRollingpigµÄblogÉÏ¿´µ½ÁËÕâÆªÎÄÕÂ, ʵÏÖÁËͬÑùµÄ¹¦ÄÜ, ²»¹ýrollingpigÊÇʹÓú¯ÊýʵÏÖµÄ.
´úÂëÈçÏÂ:

 create or replace type connstrImpl as object
      (
        currentstr varchar2(4000),
        currentseprator varchar2(8),
        static function ODCIAggregateInitialize(sctx IN OUT connstrImpl)
          return number,
        member function ODCIAggregateIterate(self IN OUT connstrImpl,
          value IN VARCHAR2) return number,
        member function ODCIAggregateTerminate(self IN connstrImpl,
          returnValue OUT VARCHAR2, flags IN number) return number,
        member function ODCIAggregateMerge(self IN OUT connstrImpl,
          ctx2 IN connstrImpl) return number
      );
      /


      create or replace type body connstrImpl is
      static function ODCIAggregateInitialize(sctx IN OUT connstrImpl)
      return number is
      begin
        sctx := connstrImpl('','/');
        return ODCIConst.Success;
      end;
      member function ODCIAggregateIterate(self IN OUT connstrImpl, value IN VARCHAR2) return number is
      begin
        if self.currentstr is null then
          self.currentstr := value;
        else
          self.currentstr := self.currentstr ||currentseprator || value;
        end if;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateTerminate(self IN connstrImpl, returnValue OUT VARCHAR2, flags IN number) return number is
      begin
        returnValue := self.currentstr;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateMerge(self IN OUT connstrImpl, ctx2 IN connstrImpl) return number is
      begin
        if ctx2.currentstr is null then
          self.currentstr := self.currentstr;
        elsif self.currentstr is null then
          self.currentstr := ctx2.currentstr;
        else
          self.currentstr := self.currentstr || currentseprator || ctx2.currentstr;
        end if;
        return ODCIConst.Success;
      end;
      end;
      /



      CREATE OR REPLACE FUNCTION connstr (input VARCHAR2) RETURN VARCHAR2
      PARALLEL_ENABLE AGGREGATE USING connstrImpl;
      /

ʹÓÃʾÀýÈçÏÂ:

SQL> select connstr(loc) from dept ;

CONNSTR(LOC)
--------------------------------------------------------------------------------
NEW YORK/DALLAS/CHICAGO/BOSTON

²Î¿¼×ÊÁÏ
Oracle® Data Cartridge Developer's Guide 10g Release 1 (10.1)  User-Defined Aggregate Functions


Ç×£¬Äú»¹Ã»ÓеǼ,Çë[µÇ¼]»ò[×¢²á]ºóÔÙ½øÐÐÆÀÂÛ