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.


Search Keys

  • sql ascii function
  • ascii values
  • sql ascii
  • string to ascii
  • sql server ascii
  • ascii to string
  • ascii value of
  • find ascii value
  • get ascii value
  • 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
5 Azaghu Varshith Data Mining SQL Server 2013 21740
6 Balan SQL Mining PHP 2012 2000
7 Geetha Programmer ASP.Net 2014 8930.9
8 Harish Karthik Project Manager MySQL 2012 8300

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
5 53 Azaghu Varshith 65
6 54 Balan 66
7 55 Geetha 71
8 56 Harish Karthik 72

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


Search Keys

  • character ascii values
  • asc function
  • sql character functions
  • oracle character functions
  • sql server character functions
  • sql char code
  • sql string functions
  • string functions
  • sql server string functions
  • sql string functions with examples
  • string functions in sql server
  • sql query string functions