ASCII

ascii(chr)

Description

The ASCII function is used to obtain the ASCII code value or Unicode code point of a specified character (chr). If the input character length is greater than 1, the function will only return the ASCII code value or Unicode code point of the first character.

Parameter Description

  • chr: Type is string, representing the character for which the ASCII code value or Unicode code point needs to be queried.

Return Result

  • Returns an integer (int), representing the ASCII code value or Unicode code point of the input character.

Usage Example

  1. Query the ASCII code value or Unicode code point of a single character:
SELECT ASCII('A'); -- Returns 65
  1. Query the ASCII values or Unicode code points of multiple characters:
SELECT ASCII('中'), ASCII('a'), ASCII('Z'); -- Returns 20013, 97, 90
  1. Query the ASCII code value or Unicode code point of special characters:
SELECT ASCII('\n'); -- Returns 10
  1. Query the ASCII code value or Unicode code point of an empty character:
SELECT ASCII(''); -- Returns 0

Notes

  • When the input character length is 1, the ASCII function will return the ASCII code value or Unicode code point of that character.
  • When the input character length is greater than 1, the ASCII function will only return the ASCII code value or Unicode code point of the first character.
  • For non-ASCII characters (such as Chinese characters), the ASCII function will return the corresponding Unicode code point.