UNICODE(Transact-SQL)

적용 대상: Microsoft Fabric의 Microsoft FabricWarehouse에 있는 SQL ServerAzure SQL DatabaseAzure SQL Managed InstanceAzure Synapse AnalyticsPlatform System(PDW) SQL 분석 엔드포인트

유니코드 표준에서 정의한 대로 입력 식에 있는 첫 글자의 정수 값을 반환합니다.

Transact-SQL 구문 표기 규칙

Syntax

UNICODE ( 'ncharacter_expression' )  

참고 항목

SQL Server 2014(12.x) 및 이전 버전에 대한 Transact-SQL 구문을 보려면 이전 버전 설명서를 참조 하세요.

인수

'ncharacter_expression'
nchar 또는 nvarchar 식입니다.

반환 형식

int

설명

SQL Server 2012(11.x) 이전의 SQL Server 버전 및 Azure SQL Database에서 UNICODE 함수는 유니코드 BMP(Basic Multilingual Plane)로 65,535개 문자를 나타낼 수 있는 000000~00FFFF 범위의 UCS-2 코드 포인트를 반환합니다. SQL Server 2012(11.x)부터 SC(보조 문자) 사용 데이터 정렬을 사용할 때 UNICODE가 000000에서 10FFFF까지 범위의 UTF-16 코드 포인트를 반환합니다. 데이터베이스 엔진의 유니코드 지원에 대한 자세한 내용은 데이터 정렬 및 유니코드 지원을 참조하세요.

A. UNICODE 및 NCHAR 함수 사용

다음 예에서는 UNICODENCHAR 함수를 사용하여 Åkergatan 24 문자열에 있는 첫 글자의 UNICODE 값을 인쇄하고 실제 첫 글자 Å를 인쇄합니다.

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

결과 집합은 다음과 같습니다.

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

B. SUBSTRING, UNICODE, CONVERT 사용

다음 예에서는 SUBSTRING, UNICODECONVERT 함수를 사용하여 Åkergatan 24 문자열에 있는 각 문자의 문자 번호, 유니코드 문자, 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(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; 

결과 집합은 다음과 같습니다.

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  

참고 항목

ASCII(Transact-SQL)
CHAR(Transact-SQL)
NCHAR(Transact-SQL)
문자열 함수(Transact-SQL)
데이터 정렬 및 유니코드 지원