ASCII_STR
The ASCII_STR function returns an ASCII version of the string in the system ASCII CCSID. The system ASCII CCSID is the SBCS ASCII CCSID on a MIXED=NO system or the MIXED ASCII CCSID on a MIXED=YES system.
The schema is SYSIBM.
- string-expression
- An
expression that returns a value of a built-in character or graphic
string. A character string must not be bit data. string-expression must
be an ASCII, EBCDIC, or Unicode string.
The argument can also be a numeric data type. The numeric argument is implicitly cast to a VARCHAR data type.
ASCII_STR returns an ASCII version of the string. Non-ASCII characters are converted to UTF-16 characters and appear in the result in the form \xxxx (or \xxxx\yyyy for surrogate characters), where xxxx and yyyy represent a UTF-16 code unit.
The result of the function is a varying-length character string in the system ASCII CCSID. If the actual length of the result string exceeds the maximum for the return type, an error occurs.
The result can be null; if the argument is null, the result is the null value.
ASCIISTR can be specified as a synonym for ASCII_STR.
SET :HV1 =
ASCII_STR(X'4869206D616D6520697320D090D0BDD0B4D180D0B5D0B9202020F0908080');
:HV1
is assigned the value 'Hi, my name is \0410\043D\0434\0440\0435\0439
\D800\DC00'. In this example, the UTF-8 characters D090, D0BD,
D0B4, D180, D0B5, and D0B9 are converted to \0410\043D\0434\0440\0435\0439
and the non-ASCII character F0908080 is converted to \D800\DC00.SET :HV1 = ASCII_STR('Hi, my name is Андрей (Andrei)');
:HV1 is assigned the value "Hi, my name is \0410\043D\0434\0440\0435\0439 (Andrei)"