ASCII
- American Standard Code for Information Interchange.
- Computer can understand only numbers.
- ASCII is the numeric representation of a character.
Syntax
SELECT CHAR(Expression)
A string function that converts an int ASCII code to a character.
Return type is CHAR.
Expression is integer value i.e. range from 0 to 255
Example
SELECT CHAR(97) AS [ASCII Character of Number 97]
SELECT ASCII('a') AS [ASCII Number of Character a]
SELECT CHAR(65) AS [ASCII Character of Number 67]
SELECT ASCII('A') AS [ASCII Number of Character A]
Output
ASCII Values
- Characters Set 0-31
First 32 Characters in the ASCII table are unprintable.
- Characters Set 32-127
Characters from 32-127 are common for all which represent letters, digits, punctuation marks & miscellaneous symbols.
- Character Set 128-255
Characters from 128-255 contains the Microsoft Latin-1 extended characters.
--Example to display All Number & ASCII characters
;WITH AllNumbers AS
(
SELECT 0 AS First_No
UNION ALL
SELECT First_No+1
FROM AllNumbers
WHERE First_No<255
)
SELECT First_No as [Numbers],
CHAR(First_No) as [ASCII Value]
FROM AllNumbers
OPTION (MAXRECURSION 255)
Syntax in Oracle
CHR(expression [using NCHAR_CS])
Syntax in IBM DB2, Sybase
CHR(Expression)