傅老師課堂:Oracle進階應用程式之去重彙總函式__C語言

來源:互聯網
上載者:User

本例實現的是連接字串,並且去掉重複的項。

彙總函式實際上就是一個對象: [sql] view plain copy create or replace type distinct_concat_type as object   (   --物件變數     cat_string varchar2(500),   --對象初始化     static function ODCIAggregateInitialize(cs_ctx In Out distinct_concat_type)       return number,   --彙總函式的迭代方法     member function ODCIAggregateIterate(self  In Out distinct_concat_type,                                          value in varchar2) return number,   --當查詢語句並行運行時,才會使用該方法,可將多個並行啟動並執行查詢結果彙總     member function ODCIAggregateMerge(self In Out distinct_concat_type,                                        ctx2 In Out distinct_concat_type)       return number,   --終止聚集合函式的處理,返回聚集合函式處理的結果     member function ODCIAggregateTerminate(self        In Out distinct_concat_type,                                            returnValue Out varchar2,                                            flags       in number)       return number   )   接著實現對象主體: [sql] view plain copy create or replace type body distinct_concat_type is     --對象初始化     static function ODCIAggregateInitialize(cs_ctx IN OUT distinct_concat_type)       return number is     begin       cs_ctx := distinct_concat_type(null);       return ODCIConst.Success;     end;        --彙總函式的迭代方法     member function ODCIAggregateIterate(self  IN OUT distinct_concat_type,                                          value IN varchar2) return number is     begin       if self.cat_string is null or (instr(self.cat_string, value, 1, 1) = 0) then         self.cat_string := self.cat_string || ',' || value;       end if;       return ODCIConst.Success;     end;        --當查詢語句並行運行時,才會使用該方法,可將多個並行啟動並執行查詢結果彙總     member function ODCIAggregateMerge(self IN OUT distinct_concat_type,                                        ctx2 IN Out distinct_concat_type)       return number is     begin       if self.cat_string is null or          (instr(self.cat_string, ctx2.cat_string, 1, 1) = 0) then         self.cat_string := self.cat_string || ',' || ctx2.cat_string;       end if;       return ODCIConst.Success;     end;        --終止聚集合函式的處理,返回聚集合函式處理的結果     member function ODCIAggregateTerminate(self        IN Out distinct_concat_type,                                            returnValue OUT varchar2,                                            flags       IN number) return number is     begin       returnValue := ltrim(rtrim(self.cat_string, ','), ',');       return ODCIConst.Success;     end;   end;  
最後定義函數,使用的是上面定義的對象: [sql] view plain copy create or replace function distinct_concat(input varchar2) return varchar2     parallel_enable     aggregate using distinct_concat_type; 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.