UNICODE(Transact-SQL)

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

구문

UNICODE ( 'ncharacter_expression' )

인수

'ncharacter_expression'

nchar 또는 nvarchar 식입니다.

반환 형식

int

1. UNICODE 및 NCHAR 함수 사용

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

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

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

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

2. 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 <= 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

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

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

참고 항목

참조

데이터 형식(Transact-SQL)
NCHAR(Transact-SQL)
문자열 함수(Transact-SQL)

관련 자료

유니코드 데이터 작업

도움말 및 정보

SQL Server 2005 지원 받기