ASCII(Transact-SQL)
문자 식에서 가장 왼쪽 문자의 ASCII 코드 값을 반환합니다.
적용 대상: SQL Server(SQL Server 2008 - current version), Windows Azure SQL 데이터베이스(최초 릴리스 - 현재 릴리스) |
구문
ASCII ( character_expression )
인수
- character_expression
char 또는 varchar 형식의 식입니다.
반환 형식
int
예
다음 예에서는 대상 문자열이 ASCII 문자 집합을 사용함을 전제로 하여 문자열 Du monde entier의 각 문자에 대한 ASCII 값과 CHAR 문자를 반환합니다.
SET TEXTSIZE 0;
SET NOCOUNT ON;
-- Create the variables for the current character string position
-- and for the character string.
DECLARE @position int, @string char(15);
-- Initialize the variables.
SET @position = 1;
SET @string = 'Du monde entier';
WHILE @position <= DATALENGTH(@string)
BEGIN
SELECT ASCII(SUBSTRING(@string, @position, 1)),
CHAR(ASCII(SUBSTRING(@string, @position, 1)))
SET @position = @position + 1
END;
SET NOCOUNT OFF;
GO
결과 집합은 다음과 같습니다.
----------- -
68 D
----------- -
117 u
----------- -
32
----------- -
109 m
----------- -
111 o
----------- -
110 n
----------- -
100 d
----------- -
101 e
----------- -
32
----------- -
101 e
----------- -
110 n
----------- -
116 t
----------- -
105 i
----------- -
101 e
----------- -
114 r