nchar (Transact-sql)

Belirtilen tamsayı kodu Unicode karakteri Unicode standardı tarafından tanımlandığı şekilde döndürür.

Konu bağlantısı simgesi Transact-SQL Sözdizim Kuralları

Sözdizimi

NCHAR ( integer_expression )

Bağımsız değişkenler

  • integer_expression
    Veritabanı harmanlama ek karakter (sc) bayrağı içermiyorsa, pozitif bir tam sayı 0 ile 65535 (0 ile 0xFFFF) budur. Bu aralığın dışında bir değer belirtilirse, null döndürülür. Takıma giren karakterler hakkında daha fazla bilgi için bkz: Harmanlama ve Unicode desteği.

    Veritabanı harmanlama ek karakter (sc) bayrağı destekliyorsa, pozitif bir tam sayı 0 ile 1114111 (0-0x10FFFF) budur. Bu aralığın dışında bir değer belirtilirse, null döndürülür.

Dönüş Türleri

nchar(1)ne zaman varsayılan veritabanı harmanlama takıma giren karakterleri desteklemez.

nvarchar(2)ne zaman varsayılan veritabanı harmanlama takıma giren karakterleri destekler.

Eğer parametre integer_expressionyalnızca bir karakter aralığı 0 - 0xFFFF, yalan döndü. Daha yüksek değerler için karşılık gelen yedek çifti için nchar döndürür. Bir yedek çifti değil inşa kullanarak NCHAR(<High surrogate>) + NCHAR(<Low Surrogate>). Bunun yerine, takıma giren karakterleri destekleyen bir veritabanı harmanlama kullanın ve yedek çifti için Unicode CODEPOINT belirtin. Aşağıdaki örnek, bir yedek çifti oluşturmak yoluyla eski stil yöntemi ve Unicode CODEPOINT belirtme tercih edilen yöntem gösterir.

CREATE DATABASE test COLLATE Finnish_Swedish_100_CS_AS_SC;
DECLARE @d nvarchar(10) = N'ㅿ'; 
-– Old style method.
SELECT NCHAR(0xD84C) + NCHAR(0xDD7F); 

-- Preferred method. 
SELECT NCHAR(143743); 

-- Alternative preferred method.
SELECT NCHAR(UNICODE(@d));  
CREATE DATABASE test COLLATE Finnish_Swedish_100_CS_AS_SC;
DECLARE @d nvarchar(10) = N'ㅿ'; 
-– Old style method.
SELECT NCHAR(0xD84C) + NCHAR(0xDD7F); 

-- Preferred method. 
SELECT NCHAR(143743); 

-- Alternative preferred method.
SELECT NCHAR(UNICODE(@d));  

Örnekler

A.nchar ve UNICODE kullanma

Aşağıdaki örnek UNICODEve NCHARyazdırmak için işlevler UNICODEdeğeri ve NCHAR(Unicode karakter) ikinci karakterin Københavnkarakter dizesi ve gerçek ikinci karakter yazdırmak ø.

DECLARE @nstring nchar(8);
SET @nstring = N'København';
SELECT UNICODE(SUBSTRING(@nstring, 2, 1)), 
   NCHAR(UNICODE(SUBSTRING(@nstring, 2, 1)));
GO

DECLARE @nstring nchar(8);
SET @nstring = N'København';
SELECT UNICODE(SUBSTRING(@nstring, 2, 1)), 
   NCHAR(UNICODE(SUBSTRING(@nstring, 2, 1)));
GO

Sonuç kümesi buradadır.

----------- - 
248         ø
(1 row(s) affected)

----------- - 
248         ø
(1 row(s) affected)

B.SUBSTRING, UNICODE, dönüştürme ve nchar kullanma

Aşağıdaki örnek SUBSTRING, UNICODE, CONVERT, ve NCHARsayısı, Unicode karakteri ve dizedeki her karakter UNICODE değeri yazdırma işlevleri København.

-- 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. This 
-- indicates that the data following the N is Unicode data.
SET @nstring = N'København';
-- Print the character number of the position of the string you are at, 
-- the actual Unicode character you are 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

-- 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. This 
-- indicates that the data following the N is Unicode data.
SET @nstring = N'København';
-- Print the character number of the position of the string you are at, 
-- the actual Unicode character you are 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

Sonuç kümesi buradadır.

Character # Unicode Character UNICODE Value
                                               
----------- ---- ----------------- ----------- 
1           K    K                 75

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
2           ø    ø                 248

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
3           b    b                 98

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
4           e    e                 101

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
5           n    n                 110

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
6           h    h                 104

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
7           a    a                 97

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
8           v    v                 118

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
9           n    n                 110

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
10          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
11          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
12          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
13          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
14          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
15          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
16          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
17          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
18          NULL                   NULL

(1 row(s) affected)

Character # Unicode Character UNICODE Value
                                               
----------- ---- ----------------- ----------- 
1           K    K                 75

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
2           ø    ø                 248

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
3           b    b                 98

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
4           e    e                 101

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
5           n    n                 110

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
6           h    h                 104

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
7           a    a                 97

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
8           v    v                 118

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
9           n    n                 110

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
10          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
11          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
12          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
13          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
14          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
15          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
16          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
17          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
18          NULL                   NULL

(1 row(s) affected)

Ayrıca bkz.

Başvuru

Veri Türleri (Transact-SQL)

Dize işlevler (Transact-sql)

UNICODE (Transact-sql)