SQL ASCII() Function


The SQL ASCII() is a function, and return a number (ascii value) that represent of a given character from query result.

The SQL ASCII() function supports or accepts only single character and character may be a alphabet, number or a symbol.

The SQL ASCII() function will take only the first character of given input, if there are multiple characters in the given input strings.

It can be used in SELECT statement as well in where clause.

You can also search these topics using sql ascii function, ascii values of characters, oracle convert to ascii, find ascii value of a character.

SQL ASCII() Syntax

For SQL SERVER / ORACLE / MY SQL

The below syntax is used to return a ascii value from a given character.


SELECT ASCII(input_character);

The below syntax is used to return a ascii value from a given table column or field from a specific table.


SELECT ASCII(input_character) FROM table_name;

For MS ACCESS

The below syntax is used to return a ascii value from a given character.


SELECT ASC(input_character);

The below syntax is used to return a ascii value from a given table column or field from a specific table.


SELECT ASC(input_character) FROM table_name;


SQL ASCII() Example - Using Expression Or Formula

The following SQL SELECT statement returns the ascii value(number) of a given input character.


SELECT ASCII('A') AS 'Ascii Value';

The result of above query is:

Ascii Value
65

SQL ASCII() Function More Example

Input Value Result
ASCII('B') 66
ASCII('a') 97
ASCII('apple') 97
ASCII('1') 49

Sample Database Table - Employee

ID EmpName Designation Dept JoinYear Salary
1 Hari Krishnan Big Data MySQL 2014 16700
2 Sakunthala Database Designer Java 2014 3890.3
3 Vinoth Kumar Manager Oracle 2012 13760
4 Keshavan Information Tech MS Access 2012 16910.2

SQL ASCII() Example - With Table Column

The following SQL SELECT statement find the ascii value of a given table column "ID" and "EmpName" from the "Employee" table:


SELECT 
ID, ASCII(ID) As 'Ascii Of ID', 
EmpName, ASCII(EmpName) As 'Ascii Of EmpName (Only First Character)' 
FROM Employee;

The result of above query is:

ID Ascii Of ID EmpName Ascii Of EmpName (Only First Character)
1 49 Hari Krishnan 72
2 50 Sakunthala 83
3 51 Vinoth Kumar 86
4 52 Keshavan 75

Note: The ASCII() function will take only the first character of given input, if there are more than one character also.

You can also search these topics using character ascii values, sql character functions, oracle character functions, sql server character functions, sql string functions, sql server string functions, sql string functions with examples, string functions in sql server, sql query string functions.