sql-server - 在 SQL Server 中的韩语单词(任何 Unicode 单词)中查找韩语字母(任何 Unicode 字符)的索引

标签 sql-server unicode sql-server-2008-r2 cjk

我需要按姓名搜索人员。这里的人名可以是英文、韩文或中文。为此,我使用了 Like搜索条件 Name如下:

select * from [MyTable] where Name like N'%t%'

以上声明是给所有包含字母t的用户.但这不适用于韩语或中文。就像我用韩文字母搜索 那么它应该给出包含这个字母的所有名称,如 **정수연, 재훈아이팟, 정원혁 테스트 7** .我尝试了以下方法,但结果为零
select * from [MyTable] where Name like N'%ㅈ%' - No Results
select PATINDEX(N'%ㅈ%',N'정수연(Mohan)') - giving value as ZERO
select Charindex(N'ㅈ',N'정수연') - giving value as ZERO

有什么办法可以在SQL Server中找到其他语言的字母表的字母吗?

我知道如何通过使用编码技术而不是 SQL 服务器在 C# 单词中找到其他语言中的字母表。请在这方面帮助我。

提前致谢。

编辑 C# 代码
public static string DecomposeSyllabels(string unicodeString) {
      try {
        //Consonant consonant only used
        string[] JLT = { "ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ" };

        // Only used a collection of neutral
        string[] JVT = { "ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ" };

        // Initial and coda consonants used in
        string[] JTT = { "", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ" };

        double SBase = 0xAC00;
        long SCount = 11172;
        int TCount = 28;
        int NCount = 588;
        string syllables = string.Empty;

        foreach (char c in unicodeString) {
          double SIndex = (int)c - SBase;
          if (0 > SIndex || SIndex >= SCount) {
            syllables = syllables + c;
            continue;
          }

          int LIndex = (int)Math.Floor(SIndex / NCount);
          int VIndex = (int)(Math.Floor((SIndex % NCount) / TCount));
          int TIndex = (int)(SIndex % TCount);
          syllables = syllables + (JLT[LIndex] + JVT[VIndex] + JTT[TIndex]);
        }

        return syllables;
      }
      catch {
        return unicodeString;
      }
    }

最佳答案

您必须分解韩语音节并将它们存储到 SQL 数据库中的单独列中(如 ㅈㅓㅇㅅㅜㅇㅕㄴ 表示 정수연)。我建议您编写一个小型自定义应用程序来解析您的数据库,分解所有韩语音节,并将结果保存到单独的列中。
编辑
下面是一些可以分解韩文音节的 Python 代码:

#!/usr/local/bin/python
# -*- coding: utf8 -*-
import codecs, sys, os, math

JLT="ㄱ,ㄲ,ㄴ,ㄷ,ㄸ,ㄹ,ㅁ,ㅂ,ㅃ,ㅅ,ㅆ,ㅇ,ㅈ,ㅉ,ㅊ,ㅋ,ㅌ,ㅍ,ㅎ".split(",")
JTT=",ㄱ,ㄲ,ㄱㅅ,ㄴ,ㄴㅈ,ㄴㅎ,ㄷ,ㄹ,ㄹㄱ,ㄹㅁ,ㄹㅂ,ㄹㅅ,ㄹㅌ,ㄹㅍ,ㄹㅎ,ㅁ,ㅂ,ㅂㅅ,ㅅ,ㅆ,ㅇ,ㅈ,ㅊ,ㅋ,ㅌ,ㅍ,ㅎ".split(",")
JVT="ㅏ,ㅐ,ㅑ,ㅒ,ㅓ,ㅔ,ㅕ,ㅖ,ㅗ,ㅘ,ㅙ,ㅚ,ㅛ,ㅜ,ㅝ,ㅞ,ㅟ,ㅠ,ㅡ,ㅢ,ㅣ".split(",")
SBase=0xAC00
SCount=11172
TCount=28
NCount=588

def HangulName(a):
 b=a.decode('utf8')
 sound=''
 for i in b:
  cp=ord(i)
  SIndex = cp - SBase
  if (0 > SIndex or SIndex >= SCount):
#  "Not a Hangul Syllable"
    pass

  LIndex = int(math.floor(SIndex / NCount))
  VIndex = int(math.floor((SIndex % NCount) / TCount))
  TIndex = int(SIndex % TCount)
  sound=sound+(JLT[LIndex] + JVT[VIndex] + JTT[TIndex]).lower()
 return sound

print HangulName("정수연")

dda$ python test.py
ㅈㅓㅇㅅㅜㅇㅕㄴ

关于sql-server - 在 SQL Server 中的韩语单词(任何 Unicode 单词)中查找韩语字母(任何 Unicode 字符)的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12579977/

相关文章:

sql-server - 如何使用计算列规范来使用 getdate() 保留日期时间值?

sql-server - SQL Server exec 关键字

sql-server - 检查用户是否是 SQL Server 中 dbo 角色的成员

sql - 删除 SQL 中的每个备用行

sql - 表变量在表中的值函数

SQL Server 在存储过程中使用定界符的简单示例

python - unicodedata.decomposition() 与 unicodedata.normalize(NFD/NFKD)?

python - 如何在 Python 中连接和输出 unicode 文本变量

python - Beautiful Soup 和 Unicode 问题

sql - 将行分组为 5 组