ASCII

ASCII is an SQL function that returns the ASCII value of a character in integral form. It is typically used for character analysis within a provided string and often leverages the ASCII standard mapping of integer values to characters.

ASCII(str)

  • str: The string from which the ASCII value for the leftmost character will be returned. It can include alphanumeric or symbol characters.

Example

SELECT ASCII('A');

Output

65

Explanation

The ASCII() function in MySQL returns the ASCII value for the specific character. In this example, ‘A’ corresponds to the ASCII value 65.

ASCII(character)

  • character: The character to be evaluated. ASCII(character) returns the ASCII value of the given character as an integer.

Example

SELECT ASCII('A') AS ASCII_Value;

Output

ascii_value
-------------
65

Explanation

The ASCII function in PostgreSQL returns the ASCII value of a specific character. In this instance, ‘A’ has been input into the function and the returned ASCII value is 65.

ASCII( string_expression )

  • string_expression: This is a string expression that represents a character. ASCII will return the ASCII code value of the leftmost character of the string. If this character does not have a corresponding ASCII value or if string_expression is NULL, then NULL will be returned.

Example

DECLARE @Demo_Variable CHAR
SET @Demo_Variable = CHAR(65)
SELECT ASCII(@Demo_Variable) AS 'ASCII_Value'

Output

| ASCII_Value |
|-------------|
| 65 |

Explanation

The code declares a character variable and assigns it the value ‘A’. It then uses the SQL ASCII function to return the ASCII value of the character, which is 65, in the column ‘ASCII_Value’.

ASCII(single_character)

  • single_character: This parameter is used to specify the character for which the ASCII equivalent value is to be found. It should be a single, non-null character string. The function returns the ASCII value of this character in the form of a number.

Example

SELECT ASCII ('oracle') FROM dual;

Output

111

Explanation

The ASCII function in Oracle returns the NUMBER code that represents the first character of the input string. In this case, ‘o’ corresponds to the ASCII value of 111.

ASCII(X)

  • x: The input string that is being converted to ASCII. This could include any character or string of characters that the user wishes to interpret as ASCII. The function SQLASCII(X) will convert this input and output the corresponding ASCII numeric value.

Example

SELECT ASCII('A') AS Sequency;

Output

Sequence
---------
65

Explanation

In the code example, the ASCII() function returns the ASCII code for the first character of the provided string. In this case, the string is ‘A’, and its corresponding ASCII value is 65, as shown in the output.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.