1

如何仅在 SQL Server 中替换小字母字符?例如,如果我有一个文本A Simple Man。文本应替换为A Söнрмï Mæо。我用下面的脚本问题是大写的也被替换了。

ALTER FUNCTION [dbo].[sf_ReplaceCharacters] (@string NVARCHAR(MAX))
RETURNS NVARCHAR(MAX)
AS
BEGIN
    DECLARE @tmpString NVARCHAR(100)
    SET @tmpString = @string 
    set @tmpString=replace(@tmpString,N'a',N'æ')
    set @tmpString=replace(@tmpString,N'b',N'в')
    set @tmpString=replace(@tmpString,N'c',N'г')
    set @tmpString=replace(@tmpString,N'd',N'д')
    set @tmpString=replace(@tmpString,N'e',N'ï')
    set @tmpString=replace(@tmpString,N'f',N'ж')
    set @tmpString=replace(@tmpString,N'g',N'з')
    set @tmpString=replace(@tmpString,N'h',N'и')
    set @tmpString=replace(@tmpString,N'i',N'ö')
    set @tmpString=replace(@tmpString,N'j',N'к')
    set @tmpString=replace(@tmpString,N'k',N'л')
    set @tmpString=replace(@tmpString,N'l',N'м')
    set @tmpString=replace(@tmpString,N'm',N'н')
    set @tmpString=replace(@tmpString,N'n',N'о')
    set @tmpString=replace(@tmpString,N'o',N'Ą')
    set @tmpString=replace(@tmpString,N'p',N'р')
    set @tmpString=replace(@tmpString,N'q',N'с')
    set @tmpString=replace(@tmpString,N'r',N'т')
    set @tmpString=replace(@tmpString,N's',N'у')
    set @tmpString=replace(@tmpString,N't',N'ф')
    set @tmpString=replace(@tmpString,N'u',N'Č')
    set @tmpString=replace(@tmpString,N'v',N'ц')
    set @tmpString=replace(@tmpString,N'w',N'ч')
    set @tmpString=replace(@tmpString,N'x',N'ш')
    set @tmpString=replace(@tmpString,N'y',N'щ')
    set @tmpString=replace(@tmpString,N'z',N'ъ')
    RETURN @tmpString
END
4

1 回答 1

1

正如马丁史密斯所说,我使用整理来使字符替换敏感。

SET @tmpString = @string 
set @tmpString=replace(@tmpString COLLATE Cyrillic_General_CS_AS,N'a',N'æ')
于 2013-05-07T11:59:04.077 回答