All Products
Search
Document Center

MaxCompute:ASCII

Last Updated:Jul 21, 2023

Returns the ASCII code of the first character in a string specified by str.

Syntax

bigint ascii(string <str>)

Parameters

str: required. A value of the STRING type. If the input value is of the BIGINT, DOUBLE, DECIMAL, or DATETIME type, the value is implicitly converted into a value of the STRING type before calculation.

Return value

A value of the BIGINT type is returned. The return value varies based on the following rules:

  • If the value of str is not of the STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME type, an error is returned.

  • If the value of str is null, null is returned.

Examples

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

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

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

Related functions

ASCII is a string function. For more information about functions related to string searches and conversion, see String functions.