Updated on 2026-11-06 GMT+08:00

ascii

The ascii function is used to return the ASCII code of the first character of the string str.

Syntax

ascii(string ) 

Parameters

Parameter

Mandatory

Type

Description

str

Yes

STRING

If the input is of type BIGINT, DOUBLE, DECIMAL, or DATETIME, it is automatically converted to STRING type before evaluation. For example, ABC.

Return Values

Returns a value of type BIGINT.

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

Example Code

  • Return the ASCII code of the first character of the string ABC. The command example is as follows.

    Returns 65.

    select ascii('ABC'); 
  • The input parameter is NULL. The command example is as follows.

    Returns NULL.

    select ascii(null);