NCHAR(Transact-SQL)

유니코드 표준에서 정의된 대로 지정된 정수 코드에 해당하는 유니코드 문자를 반환합니다.

항목 링크 아이콘Transact-SQL 구문 표기 규칙

구문

NCHAR ( integer_expression )

인수

  • integer_expression
    0 – 65535 범위의 양의 정수입니다. 이 범위 밖의 값을 지정하면 Null 값이 반환됩니다.

반환 형식

nchar(1)

1. NCHAR 및 UNICODE 사용

다음 예에서는 UNICODE 및 NCHAR 함수를 사용하여 København 문자열에 있는 두 번째 문자의 UNICODE 값과 NCHAR(유니코드 문자)를 인쇄하고 실제 두 번째 문자인 ø를 인쇄하는 방법을 보여 줍니다.

DECLARE @nstring nchar(8)
SET @nstring = N'København'
SELECT UNICODE(SUBSTRING(@nstring, 2, 1)), 
   NCHAR(UNICODE(SUBSTRING(@nstring, 2, 1)))
GO

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

----------- - 
248         ø(1 row(s) affected)

2. SUBSTRING, UNICODE, CONVERT 및 NCHAR 사용

다음 예에서는 SUBSTRING, UNICODE, CONVERT 및 NCHAR 함수를 사용하여 København 문자열에 있는 각 문자의 문자 번호, 유니코드 문자 및 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(9)
-- 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. This 
-- indicates that the data following the N is Unicode data.
SET @nstring = N'København'
-- 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)
   BEGIN
   SELECT @position, 
      NCHAR(UNICODE(SUBSTRING(@nstring, @position, 1))),
      CONVERT(NCHAR(17), SUBSTRING(@nstring, @position, 1)),
      UNICODE(SUBSTRING(@nstring, @position, 1))
   SELECT @position = @position + 1
   END
GO

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

Character # Unicode Character UNICODE Value
                                               
----------- ---- ----------------- ----------- 
1           K    K                 75

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
2           ø    ø                 248

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
3           b    b                 98

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
4           e    e                 101

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
5           n    n                 110

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
6           h    h                 104

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
7           a    a                 97

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
8           v    v                 118

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
9           n    n                 110

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
10          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
11          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
12          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
13          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
14          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
15          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
16          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
17          NULL                   NULL

(1 row(s) affected)

                                               
----------- ---- ----------------- ----------- 
18          NULL                   NULL

(1 row(s) affected)