Skip to main content


A string function that returns the integer ASCII code value of the first (leftmost) character of a string expression.


{fn ASCII(string-expression)}


Argument Description
string-expression A string expression, which can be the name of a column, a string literal, or the result of another scalar function, where the underlying data type can be represented as any character type (such as CHAR or VARCHAR). A string expression of type CHAR or VARCHAR.


ASCII returns NULL if passed a NULL or an empty string value. The returning of NULL for empty string is consistent with SQL Server.

Note that ASCII can be invoked as an ODBC scalar function (with the curly brace syntax) or as an SQL general function.


The following examples both returns 90, which is the ASCII value of the character Z:

SELECT {fn ASCII('ZEBRA')} AS AsciiCode 

Caché SQL converts numerics to canonical form before performing ASCII conversion. The following example returns 55, which is the ASCII value of the number 7:

SELECT ASCII(+007) AS AsciiCode

This number parsing is not done if the numeric is presented as a string. The following example returns 43, which is the ASCII value of the plus (+) character:

SELECT ASCII('+007') AS AsciiCode 

See Also

FeedbackOpens in a new tab