ASCII

更新时间:
复制 MD 格式

Returns the ASCII code of the first character in a string.

Syntax

bigint ascii(string <str>)

Parameters

ParameterRequiredTypeDescription
strYesSTRINGThe input string. If the value is BIGINT, DOUBLE, DECIMAL, or DATETIME type, it is implicitly converted to STRING before the function runs.

Return value

Returns a BIGINT value.

ConditionReturn value
str is a non-empty stringASCII code of the first character
str is nullnull
str is not STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME typeError

Examples

  • Example 1: Return the ASCII code of the first character in the string abcde.

    -- The return value is 97.
    select ascii('abcde');
  • Example 2: An input parameter is set to null.

    -- The return value is null.
    select ascii(null);

Related functions

ascii is a string function. For other string functions, see String functions.