How can I filter a column by Chinese-Japanese like characters? I am trying to do something like
SELECT * FROM my_table WHERE column LIKE '%[A-Za-z]%'
Is it possible for Chinese or Japanese characters?
How can I filter a column by Chinese-Japanese like characters? I am trying to do something like
SELECT * FROM my_table WHERE column LIKE '%[A-Za-z]%'
Is it possible for Chinese or Japanese characters?
3条答案
按热度按时间m0rkklqb1#
When working with unicode string you will always need to prefix your string with
N
to tell sql server explicitly that there can be unicode characters in the operation. INSERT, UPDATE, SELECT and DELETE its true for all operations.In your case when selecting data, in where clause you will need to prefix the Search string with
N
. Something like this....guz6ccqo2#
Below may work as it did for me.
The
len
function may ignore trailing whitespaces so it's best to trim it before measuring the length. Above came from advise on a Japanese web page.aemubtdh3#
I ended up writing a function to parse each character of a string and check if the UNICODE() value is within the range of CJK characters. This doesn't definitively make it only Chinese, but does get Hanzi/Kanji characters. I composited a few ranges that are consecutive.
Unicode Block descriptions: http://zuga.net/articles/unicode-all-blocks/?highlight=104
Some of these integer values exceed the range which SQL can interpret with the UNICODE and NCHAR functions. I welcome constructive feedback to this SQL function.
SQL Function:
Example usage:
Results:
Pepsi (English) = 0
ペプシ (Japanese (Katakana)) = 0
百事可乐 (Chinese) = 1