Poznámka:
Přístup k této stránce vyžaduje autorizaci. Můžete se zkusit přihlásit nebo změnit adresáře.
Přístup k této stránce vyžaduje autorizaci. Můžete zkusit změnit adresáře.
Platí pro:SQL Server
Azure SQL Database
Spravovaná instance Azure SQL
Azure Synapse Analytics
Analytics Platform System (PDW)
Koncový bod analýzy SQL v Microsoft Fabric
Sklad v Microsoft Fabric
Databáze SQL v Microsoft Fabric
Vrací celočíselnou hodnotu, jak je definována standardem Unicode, pro první znak vstupního výrazu.
Syntaxe
UNICODE ( 'ncharacter_expression' )
Arguments
'ncharacter_expression'
Je výraz nchar nebo nvarchar .
Návratové typy
int
Poznámky
Ve verzích SQL Serveru starších než SQL Server 2012 (11.x) a v Azure SQL Database funkce UNICODE vrací kódový bod UCS-2 v rozsahu 000000 až 00FFFF, který je schopen reprezentovat 65 535 znaků v Unicode Basic Multilingual Plane (BMP). Počínaje SQL Server 2012 (11.x), při použití kolací s povolenou Supplementary Character (SC), UNICODE vrací kódový bod UTF-16 v rozsahu 000000 až 10FFFF. Pro více informací o podpoře Unicode v databázovém enginu viz Kolace a podpora Unicode.
Examples
A. Použití UNICODE a funkce NCHAR
Následující příklad používá funkce a k UNICODE vytištění hodnoty UNICODE prvního znaku řetězce Åkergatan 24, a k vytištění skutečného prvního znaku, Å.NCHAR
DECLARE @nstring NCHAR(12);
SET @nstring = N'Åkergatan 24';
SELECT UNICODE(@nstring), NCHAR(UNICODE(@nstring));
Tady je soubor výsledků.
----------- -
197 Å
B. Použití SUBSTRING, UNICODE a CONVERT
Následující příklad používá SUBSTRINGfunkce , UNICODE, a CONVERT k vytištění čísla znaku, znaku Unicode a hodnoty UNICODE každého znaku v řetězci Å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 <= LEN(@nstring)
-- While these are still characters in the character string,
BEGIN;
SELECT @position AS [position],
SUBSTRING(@nstring, @position, 1) AS [character],
UNICODE(SUBSTRING(@nstring, @position, 1)) AS [code_point];
SET @position = @position + 1;
END;
Tady je soubor výsledků.
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
Viz také
ASCII (Transact-SQL)
ZNAK (Transact-SQL)
NCHAR (Transact-SQL)
Podpora kolace a kódování Unicode