1

라틴계에서 키릴 문자로 변환하는 ms sql 함수를 찾고 있습니다. 누구든지 해결책을 완료 했습니까? (예를 들어, 'spasibo'-> 'спасибо')라틴계에서 키릴 문자로의 SQL 함수

+3

왜 당신은 SQL에서 그런 종류의 일을할까요? –

+2

키릴 문자는 언어가 아니며 알파벳입니다. 우크라이나어 대 러시아어 대 슬라브어가 아닌 키릴 문자에서 라틴어로의 음역에는 여러 가지 규칙이 있습니다. 라틴어에서 키릴 문자로 음역을하기 전에 특정 언어를 알아야한다고 생각합니다. – Olaf

+0

올라프, 러시아어가 필요해. – Yara

답변

1
CREATE FUNCTION dbo.ToCyrillic 
(
    @str Nvarchar(MAX) 
) 
RETURNS Nvarchar(MAX) 
AS 
BEGIN 
    -- Declare the return variable here 
    DECLARE @inputLength int 
    DECLARE @i int 
    DECLARE @latinSymbol nVarchar(2) 
    DECLARE @cyrillicSymbol nVarchar(2) 
    DECLARE @outputValue nVarchar(MAX) 

    SET @outputValue=N'' 
    SET @inputLength=LEN(@str) 
    SET @i=1 

    DECLARE @TransTable table (upperCyr nvarchar(2) COLLATE Cyrillic_General_CI_AS, 
           lowerCyr nvarchar(2) COLLATE Cyrillic_General_CI_AS, 
           lowerLat nvarchar(2), cid int PRIMARY KEY IDENTITY(1,1)) 

    insert into @TransTable values (N'А', N'а', N'a') 
    insert into @TransTable values (N'Б', N'б', N'b') 
    insert into @TransTable values (N'В', N'в', N'v') 
    insert into @TransTable values (N'Г', N'г', N'g') 
    insert into @TransTable values (N'Д', N'д', N'd') 
    insert into @TransTable values (N'Ђ', N'ђ', N'đ') 
    insert into @TransTable values (N'Е', N'е', N'e') 
    insert into @TransTable values (N'Ж', N'ж', N'ž') 
    insert into @TransTable values (N'З', N'з', N'z') 
    insert into @TransTable values (N'И', N'и', N'i') 
    insert into @TransTable values (N'Ј', N'ј', N'j') 
    insert into @TransTable values (N'К', N'к', N'k') 
    insert into @TransTable values (N'Л', N'л', N'l') 
    insert into @TransTable values (N'Љ', N'љ', N'lj') 
    insert into @TransTable values (N'М', N'м', N'm') 
    insert into @TransTable values (N'Н', N'н', N'n') 
    insert into @TransTable values (N'Њ', N'њ', N'nj') 
    insert into @TransTable values (N'О', N'о', N'o') 
    insert into @TransTable values (N'П', N'п', N'p') 
    insert into @TransTable values (N'Р', N'р', N'r') 
    insert into @TransTable values (N'С', N'с', N's') 
    insert into @TransTable values (N'Т', N'т', N't') 
    insert into @TransTable values (N'Ћ', N'ћ', N'ć') 
    insert into @TransTable values (N'У', N'у', N'u') 
    insert into @TransTable values (N'Ф', N'ф', N'f') 
    insert into @TransTable values (N'Х', N'х', N'h') 
    insert into @TransTable values (N'Ц', N'ц', N'c') 
    insert into @TransTable values (N'Ч', N'ч', N'č') 
    insert into @TransTable values (N'Џ', N'џ', N'dž') 
    insert into @TransTable values (N'Ш', N'ш', N'š') 


    WHILE (@i<[email protected]) 
    BEGIN 
     SET @latinSymbol=SUBSTRING(@str,@i,1) 
     SET @[email protected] -- If not found below, then use that char (e.g. numbers etc) 

     IF ((@latinSymbol COLLATE Croatian_CS_AS)=UPPER(@latinSymbol)) 
     BEGIN 
      SELECT TOP 1 @cyrillicSymbol=upperCyr FROM @TransTable WHERE lowerlat=lower(@latinSymbol) ORDER BY CID 
     END 
     ELSE 
     BEGIN 
      SELECT TOP 1 @cyrillicSymbol=lowerCyr FROM @TransTable WHERE lowerlat=lower(@latinSymbol) ORDER BY CID 
     END 
     SET @[email protected]+1 
     set @[email protected][email protected] 
    END 

    RETURN @outputValue 

END 
+0

세르비아어 알파벳에 대한 키릴 문자로의 음역입니다. 다른 알파벳에도이 함수를 자유롭게 적용 할 수 있습니다. –

+0

사용 예제 : select transliterated = dbo.ToCyrillic ('게으른 개를 뛰어 넘은 빠른 여우') COLLATE Cyrillic_General_CI_AS –

0

그것은 좋은 기능 dbo.ToCyrillic는하지만 충분하지. 트리 예외는 Љ = lj, Њ = nj, Џ = dž입니다. 이 예외 ALTER 기능 dbo.ToCyrillic입니다 :

-- select dbo.ToCyrillic('Ljubav nJače džače') 

ALTER FUNCTION [dbo].[ToCyrillic](@str Nvarchar(MAX)) 
    RETURNS Nvarchar(MAX) 
    AS 
BEGIN 
-- Declare the return variable here 
DECLARE @inputLength int 
DECLARE @i int 
DECLARE @latinSymbol nVarchar(2) 
DECLARE @latinSymbol2 nVarchar(2) 
set @latinSymbol2=null 
DECLARE @cyrillicSymbol nVarchar(2) 
DECLARE @outputValue nVarchar(MAX) 
SET @outputValue=N'' 
SET @inputLength=LEN(@str) 
SET @i=1 

DECLARE @TransTable table (upperCyr nvarchar(2) COLLATE Cyrillic_General_CI_AS, 
          lowerCyr nvarchar(2) COLLATE Cyrillic_General_CI_AS, 
          lowerLat nvarchar(2), cid int PRIMARY KEY IDENTITY(1,1)) 

insert into @TransTable values (N'А', N'а', N'a') 
insert into @TransTable values (N'Б', N'б', N'b') 
insert into @TransTable values (N'В', N'в', N'v') 
insert into @TransTable values (N'Г', N'г', N'g') 
insert into @TransTable values (N'Д', N'д', N'd') 
insert into @TransTable values (N'Ђ', N'ђ', N'đ') 
insert into @TransTable values (N'Е', N'е', N'e') 
insert into @TransTable values (N'Ж', N'ж', N'ž') 
insert into @TransTable values (N'З', N'з', N'z') 
insert into @TransTable values (N'И', N'и', N'i') 
insert into @TransTable values (N'Ј', N'ј', N'j') 
insert into @TransTable values (N'К', N'к', N'k') 
insert into @TransTable values (N'Л', N'л', N'l') 
insert into @TransTable values (N'Љ', N'љ', N'lj') 
insert into @TransTable values (N'М', N'м', N'm') 
insert into @TransTable values (N'Н', N'н', N'n') 
insert into @TransTable values (N'Њ', N'њ', N'nj') 
insert into @TransTable values (N'О', N'о', N'o') 
insert into @TransTable values (N'П', N'п', N'p') 
insert into @TransTable values (N'Р', N'р', N'r') 
insert into @TransTable values (N'С', N'с', N's') 
insert into @TransTable values (N'Т', N'т', N't') 
insert into @TransTable values (N'Ћ', N'ћ', N'ć') 
insert into @TransTable values (N'У', N'у', N'u') 
insert into @TransTable values (N'Ф', N'ф', N'f') 
insert into @TransTable values (N'Х', N'х', N'h') 
insert into @TransTable values (N'Ц', N'ц', N'c') 
insert into @TransTable values (N'Ч', N'ч', N'č') 
insert into @TransTable values (N'Џ', N'џ', N'dž') 
insert into @TransTable values (N'Ш', N'ш', N'šˇ') 


WHILE (@i<[email protected]) 
BEGIN 
    SET @latinSymbol=SUBSTRING(@str,@i,1) 
    SET @[email protected] -- If not found below, then use that char (e.g. numbers etc) 

     -- exceptions Љ,Њ,Џ 
if (@i+1<[email protected]) set @latinSymbol2=SUBSTRING(@str,@i+1,1)  
if lower(@[email protected]) in ('lj','nj','dž')  
    begin 
     if ((@latinSymbol COLLATE Croatian_CS_AS)=UPPER(@latinSymbol)) 
      BEGIN 
      SELECT TOP 1 @cyrillicSymbol=upperCyr FROM @TransTable WHERE lowerlat=lower(@[email protected]) ORDER BY CID 
      END 
      ELSE 
      BEGIN 
      SELECT TOP 1 @cyrillicSymbol=lowerCyr FROM @TransTable WHERE lowerlat=lower(@[email protected]) ORDER BY CID 
      END  
      SET @[email protected]+2  
     end 
    else--end exceptions 
    begin 
     IF ((@latinSymbol COLLATE Croatian_CS_AS)=UPPER(@latinSymbol)) 
     BEGIN 
     SELECT TOP 1 @cyrillicSymbol=upperCyr FROM @TransTable WHERE lowerlat=lower(@latinSymbol) ORDER BY CID 
     END 
     ELSE 
     BEGIN 
     SELECT TOP 1 @cyrillicSymbol=lowerCyr FROM @TransTable WHERE lowerlat=lower(@latinSymbol) ORDER BY CID 
     END 
     SET @[email protected]+1 
    end 
    set @[email protected][email protected] 
END 

RETURN @outputValue 

END