Returns the ASCII code of the first character in a string.
Syntax
bigint ascii(string <str>)Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
str | Yes | STRING | The 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.
| Condition | Return value |
|---|---|
str is a non-empty string | ASCII code of the first character |
str is null | null |
str is not STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME type | Error |
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.
该文章对您有帮助吗?