Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
Van toepassing op:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
SQL Analytics-eindpunt in Microsoft Fabric
Magazijn in Microsoft Fabric
SQL-database in Microsoft Fabric
Geeft de gehele waarde terug, zoals gedefinieerd door de Unicode-standaard, voor het eerste teken van de invoerexpressie.
Transact-SQL syntaxis-conventies
Syntaxis
UNICODE ( 'ncharacter_expression' )
Arguments
'ncharacter_expression'
Is een nchar- of nvarchar-uitdrukking .
Retourtypen
int
Opmerkingen
In versies van SQL Server van vóór SQL Server 2012 (11.x) en in Azure SQL Database, geeft de UNICODE-functie een UCS-2 codepunt terug in het bereik 000000 tot en met 00FFFF dat in staat is de 65.535 tekens in het Unicode Basic Multilingual Plane (BMP) weer te geven. Vanaf SQL Server 2012 (11.x), bij gebruik van Supplementary Character (SC) geschikte collaties, geeft UNICODE een UTF-16 codepunt terug in het bereik 000000 tot en met 10FFFF. Voor meer informatie over Unicode-ondersteuning in de Database Engine, zie Collation en Unicode Support.
Voorbeelden
Eén. Met behulp van UNICODE en de NCHAR-functie
Het volgende voorbeeld gebruikt de UNICODE functies en NCHAR om de UNICODE-waarde van het eerste teken van de string Åkergatan 24af te drukken, en om het daadwerkelijke eerste teken, Å.
DECLARE @nstring NCHAR(12);
SET @nstring = N'Åkergatan 24';
SELECT UNICODE(@nstring), NCHAR(UNICODE(@nstring));
Hier is het resultatenoverzicht.
----------- -
197 Å
B. Met behulp van SUBSTRING, UNICODE en CONVERT
Het volgende voorbeeld gebruikt de SUBSTRING, , en CONVERT functies om het tekennummer, het Unicode-teken en de UNICODE-waarde van elk van de tekens in de string Åkergatan 24UNICODEaf te drukken.
-- 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;
Hier is het resultatenoverzicht.
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
Zie ook
ASCII (Transact-SQL)
CHAR (Transact-SQL)
NCHAR (Transact-SQL)
tekenreeksfuncties (Transact-SQL)
Sorteervolgorde en Unicode-ondersteuning