Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section


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:

Copy code to clipboard
SELECT {fn ASCII('ZEBRA')} AS AsciiCode 
Copy code to clipboard

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
Copy code to clipboard

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 
Copy code to clipboard

See Also