PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References
PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References

PostgreSQL ASCII() Function



The PostgreSQL ASCII() function returns the ASCII value of specified character. If a string is entered, the function returns the ASCII value for the first character of the string only.

For UTF8 it returns the Unicode code point of the character. For other multibyte encodings, the argument must be an ASCII character.

Syntax

ASCII(character)

Parameters

character Required. Specify the character to return the ASCII value for. If more than one character is entered, the function will only return the value for the first character.

Return Value

Returns the ASCII value of a character.

Example 1:

The example below shows the usage of ASCII() function.

SELECT ASCII('A');
Result: 65

SELECT ASCII('1');
Result: 49

SELECT ASCII('AlphaCodingSkills.com');
Result: 65

SELECT ASCII('123');
Result: 49

SELECT ASCII('@gmail.com');
Result: 64

Example 2:

Consider a database table called Employee with the following records:

EmpIDNameCity
1JohnLondon
2MarryNew York
3JoParis
4KimAmsterdam
5RameshNew Delhi
6HuangBeijing

In the query below, the ASCII() function is used to get the ASCII value of first character of Name column value of Employee table.

SELECT *, ASCII(Name) AS ASCII_Val FROM Employee;

This will produce the result as shown below:

EmpIDNameCityASCII_Val
1JohnLondon74
2MarryNew York77
3JoParis74
4KimAmsterdam75
5RameshNew Delhi82
6HuangBeijing72

❮ PostgreSQL Functions