自定義聚合函式

2021-08-30 16:04:04 字數 1898 閱讀 9337

新建database project

新建concatenate class

using system;

using system.data;

using microsoft.sqlserver.server;

using system.data.sqltypes;

using system.io;

using system.text;

[serializable]

[sqluserdefinedaggregate(

format.userdefined, //use clr serialization to serialize the intermediate result

isinvarianttonulls = true, //optimizer property

isinvarianttoduplicates = false, //optimizer property

isinvarianttoorder = false, //optimizer property

maxbytesize = 8000) //maximum size in bytes of persisted value

]public class concatenate : ibinaryserialize

///

/// accumulate the next value, not if the value is null

///

///

public void accumulate(sqlstring value)

}///

/// merge the partially computed aggregate with this aggregate.

///

///

public void merge(concatenate other)

///

/// called at the end of aggregation, to return the results of the aggregation.

///

///

public sqlstring terminate()

return new sqlstring(output);

}public void read(binaryreader r)

public void write(binarywriter w)

}編譯 concatenate class

註冊aggregate.dll'

create assembly myagg from 'c:\aggregate.dll'

gocreate aggregate myagg (@input nvarchar(200)) returns nvarchar(max)

external name myagg.concatenate

其中:第乙個、第三個myagg 是程式集名稱

concatenate是類名

第二個myagg是聚合函式名稱

concatenate為類名

如果註冊失敗或執行前失敗(禁止在 .net framework 中執行使用者**。啟用 "clr enabled" 配置選項 ),先執行以下sql

exec sp_configure 'show advanced options', '1';

goreconfigure;

goexec sp_configure 'clr enabled', '1'

goreconfigure;

exec sp_configure 'show advanced options', '1';

go刪除註冊

drop aggregate myagg

然後到程式集中將其刪除

自定義聚合函式

create or replace type string sum obj as object 聚合函式的實質就是乙個物件 sum string varchar2 4000 static function odciaggregateinitialize v self in out string su...

groupby agg 自定義聚合函式

college pd.read csv data college.csv college.head instnm city stabbr hbcu menonly womenonly relaffil satvrmid satmtmid distanceonly ugds 2mor ugds nra...

Pandas groupby 自定義聚合函式

自定義聚合函式,n.i.o 出現次數0 0 n.i.o 出現次數1 進一步判斷 n.i.o 出現次數大於2 2 此函式需進一步擴充套件,出現次數大於2的,需要根據計畫頻率,判斷是否在一次連續測試內 defpeak peak arr,df 判斷arr的series值中是否包含 n.i.o x list...