UNICODE (Transact-sql)

Giriş deyimin ilk karakteri Unicode standardı tarafından tanımlanan tamsayı değeri döndürür.

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

Sözdizimi

UNICODE ( 'ncharacter_expression' )

Bağımsız değişkenler

  • 'ncharacter_expression'
    Olan bir ncharya nvarcharifade.

Dönüş Türleri

int

Açıklamalar

Sürümlerinde SQL Serverdaha önce SQL Server 2012, 0 ve 0xFFFF ile ucs-2 CODEPOINT UNICODE işlev verir. De SQL Server 2012ve sonraki sürümleri, sc alfabe, kullanırken UNICODE utf-16 CODEPOINT aralığı 0 ile 0x10FFFF.

Örnekler

A.UNICODE ve nchar işlevini kullanma

Aşağıdaki örnek UNICODEve NCHARişlevleri ilk karakteri UNICODE değeri yazdırma Åkergatan24-karakter dizesi ve gerçek ilk karakter yazdırmak Å.

DECLARE @nstring nchar(12);
SET @nstring = N'Åkergatan 24';
SELECT UNICODE(@nstring), NCHAR(UNICODE(@nstring));

DECLARE @nstring nchar(12);
SET @nstring = N'Åkergatan 24';
SELECT UNICODE(@nstring), NCHAR(UNICODE(@nstring));

Sonuç kümesi buradadır.

----------- - 
197         Å

----------- - 
197         Å

B.SUBSTRING, UNICODE ve convert kullanma

Aşağıdaki örnek SUBSTRING, UNICODE, ve CONVERTişlevleri karakter sayısı Unicode karakteri ve her karakter dizesindeki UNICODE değeri yazdırma Åkergatan 24.

-- 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(12);
-- 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'Åkergatan 24';
-- 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)
-- While these are still characters in the character string,
   BEGIN;
   SELECT @position, 
      CONVERT(char(17), SUBSTRING(@nstring, @position, 1)),
      UNICODE(SUBSTRING(@nstring, @position, 1));
   SELECT @position = @position + 1;
   END;

-- 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(12);
-- 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'Åkergatan 24';
-- 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)
-- While these are still characters in the character string,
   BEGIN;
   SELECT @position, 
      CONVERT(char(17), SUBSTRING(@nstring, @position, 1)),
      UNICODE(SUBSTRING(@nstring, @position, 1));
   SELECT @position = @position + 1;
   END;

Sonuç kümesi buradadır.

Character # Unicode Character UNICODE Value
                                          
----------- ----------------- ----------- 
1           Å                 197         
                                          
----------- ----------------- ----------- 
2           k                 107         
                                          
----------- ----------------- ----------- 
3           e                 101         
                                          
----------- ----------------- ----------- 
4           r                 114         
                                          
----------- ----------------- ----------- 
5           g                 103         
                                          
----------- ----------------- ----------- 
6           a                 97          
                                          
----------- ----------------- ----------- 
7           t                 116         
                                          
----------- ----------------- ----------- 
8           a                 97          
                                          
----------- ----------------- ----------- 
9           n                 110         
                                          
----------- ----------------- ----------- 
10                            32          
                                          
----------- ----------------- ----------- 
11          2                 50          
                                          
----------- ----------------- ----------- 
12          4                 52

Character # Unicode Character UNICODE Value
                                          
----------- ----------------- ----------- 
1           Å                 197         
                                          
----------- ----------------- ----------- 
2           k                 107         
                                          
----------- ----------------- ----------- 
3           e                 101         
                                          
----------- ----------------- ----------- 
4           r                 114         
                                          
----------- ----------------- ----------- 
5           g                 103         
                                          
----------- ----------------- ----------- 
6           a                 97          
                                          
----------- ----------------- ----------- 
7           t                 116         
                                          
----------- ----------------- ----------- 
8           a                 97          
                                          
----------- ----------------- ----------- 
9           n                 110         
                                          
----------- ----------------- ----------- 
10                            32          
                                          
----------- ----------------- ----------- 
11          2                 50          
                                          
----------- ----------------- ----------- 
12          4                 52

Ayrıca bkz.

Başvuru

nchar (Transact-sql)

Dize işlevler (Transact-sql)

Diğer Kaynaklar

Working with Unicode Data