熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> MySQL >> 正文

SQL2005CLR函數擴展-繁簡轉換的實現代碼

2022-06-13   來源: MySQL 

  這個方法比較簡單用MicrosoftVisualBasic命名空間下強大的字符串處理函數就可以了
c#代碼如下編譯為BigConvertordll

復制代碼 代碼如下:
using System;
using SystemDataSqlTypes;
using MicrosoftSqlServerServer;

public partial class UserDefinedFunctions
{
[MicrosoftSqlServerServerSqlFunction ]
public static SqlString BigToGB(SqlString inString)
{
if (inStringIsNull) return SqlString Null;
return (MicrosoftVisualBasicStrings StrConv(inStringValue MicrosoftVisualBasicVbStrConv SimplifiedChinese ));
}
[MicrosoftSqlServerServerSqlFunction ]
public static SqlString GBToBig(SqlString inString)
{
if (inStringIsNull) return SqlString Null;
return (MicrosoftVisualBasicStrings StrConv(inStringValue MicrosoftVisualBasicVbStrConv TraditionalChinese ));
}
};

  

部署代碼如下

復制代碼 代碼如下:
CREATE ASSEMBLY BigConvertor FROM E:/sqlclrdata/BigConvertordll WITH PERMISSION_SET = UnSAFE;

go
CREATE FUNCTION dbo xfn_BigToGB
(
@value nvarchar ( max )
)
RETURNS nvarchar ( max )
AS EXTERNAL NAME BigConvertor UserDefinedFunctions BigToGB
go
CREATE FUNCTION dbo xfn_GBToBig
(
@value nvarchar ( max )
)
RETURNS nvarchar ( max )
AS EXTERNAL NAME BigConvertor UserDefinedFunctions GBToBig

go

  

測試代碼如下

/* 測試 */
select dbo xfn_GBToBig( 簡體與繁體文的轉換 )
簡體與繁體文的轉換
select dbo xfn_BigToGB( 簡體與繁體文的轉換 )
簡體與繁體文的轉換


From:http://tw.wingwit.com/Article/program/MySQL/201311/29553.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.