根据 Unicode 标准所进行的定义,用给定整数代码返回 Unicode 字符。
NCHAR ( integer_expression )
integer_expression
介于 0 与 65535 之间的所有正整数。如果指定了超出此范围的值,将返回 NULL。
nchar(1)
下面的示例使用 UNICODE 和 NCHAR 函数打印字符串 Køenhavn 第二个字符的 UNICODE 值和 NCHAR(Unicode 字符),并打印实际的第二个字符ø。
DECLARE @nstring nchar(8)
ø
SET @nstring = N'Kbenhavn'
SELECT UNICODE(SUBSTRING(@nstring, 2, 1)),
NCHAR(UNICODE(SUBSTRING(@nstring, 2, 1)))
GO
下面是结果集:
----------- -
ø
248(1 row(s) affected)
下面的示例使用 SUBSTRING、UNICODE、CONVERT 和 NCHAR 函数打印字符串 Køenhavn 的字符数、Unicode 字符以及每个字符的 UNICODE 值。
-- The @position variable holds the position of the character currently
ø
-- being processed. The @nstring variable is the Unicode character
-- string to process.
DECLARE @position int, @nstring nchar(9)
-- Initialize the current position variable to the first character in
-- the string.
SET @position = 1
-- Initialize the character string variable to the string to process.
-- Notice that there is an N before the start of the string, which
-- indicates that the data following the N is Unicode data.
SET @nstring = N'Kbenhavn'
-- Print the character number of the position of the string you're at,
-- the actual Unicode character you're processing, and the UNICODE value -- for this particular character.
PRINT 'Character #' + ' ' + 'Unicode Character' + ' ' + 'UNICODE Value'
WHILE @position <= DATALENGTH(@nstring)
BEGIN
SELECT @position,
NCHAR(UNICODE(SUBSTRING(@nstring, @position, 1))),
CONVERT(NCHAR(17), SUBSTRING(@nstring, @position, 1)),
UNICODE(SUBSTRING(@nstring, @position, 1))
SELECT @position = @position + 1
END
GO
下面是结果集:
相关文章Character # Unicode Character UNICODE Value
ø
----------- ----------------- -----------
1 K 75
----------- ----------------- -----------
2248
----------- ----------------- -----------
3 b 98
----------- ----------------- -----------
4 e 101
----------- ----------------- -----------
5 n 110
----------- ----------------- -----------
6 h 104
----------- ----------------- -----------
7 a 97
----------- ----------------- -----------
8 v 118
----------- ----------------- -----------
9 n 110
----------- ----------------- -----------
10 (null) (null)
----------- ----------------- -----------
11 (null) (null)
----------- ----------------- -----------
12 (null) (null)
----------- ----------------- -----------
13 (null) (null)
----------- ----------------- -----------
14 (null) (null)
----------- ----------------- -----------
15 (null) (null)
----------- ----------------- -----------
16 (null) (null)
----------- ----------------- -----------
17 (null) (null)
----------- ----------------- -----------
18 (null) (null)