Scalar. Converts a given value to a String.
This function coverts values as follows:
For an Integer or Long value, you can include an optional format string that specifies the format for the string output. The format string follows the ISO standard for fprintf. The default for Integer expressions is "%ld", while the default for Long expressions is "%lld". Note: Sybase CEP Engine follows whatever variations or restrictions are placed on printf for the operating system on which your Sybase CEP Server is being run, so those variations apply to this format string as well. Also note that an incorrect format string may cause Sybase CEP Server to exit.
For a Timestamp value, you can include a format string to control the output format of the string. The default format is YYYY-MM-DD HH24:MI:SS.FF. See Timestamp Format Codes for more information. There is also an optional time zone string option. See "Sybase CEP Time Zone Database" in the Sybase CEP Integration Guide for more information about valid time zone strings.
This function coverts a BLOB value to a String containing hexadecimal characters.
See XMLSERIALIZE for information about converting an XML value to a String.
For a Float value, you can include an optional format string that specifies the format for the output of the floating point number. The format string can include the following characters:
Character |
Description |
---|---|
. or D |
Returns a decimal point in the specified position. Only one decimal point can be specified, or the output will contain number signs instead of the value. |
9 |
Replaced in the output by a single digit of the value. The value is returned with as many characters as there are 9s in the format string. If the value is positive, a leading space is included to the left of the value. If the value is negative, a leading minus sign is included to the left of the value. Excess 9s to the left of the decimal point are replaced with spaces, while excess 9s to the right of the decimal point are replaced with zeroes. Insufficient 9s to the left of the decimal point returns number signs instead of the value, while insufficient 9s to the right of the decimal point result in rounding. Use FM to strip leading spaces. |
0 |
To the left of the decimal point, replaced in the output by a single digit of the value or a zero, if the value does not have a digit in the position of the zero. To the right of the decimal point, treated as a 9. If the value is positive, a leading space is included to the left of the value. If the value is negative, a leading minus sign is included to the left of the value. Use FM to strip leading spaces. |
EEEE |
Returns the value in scientific notation. The output for this format always includes a single digit before the decimal. Combine with a decimal point and 9s to specify precision. 9s to the left of the decimal point are ignored. Must be placed at the end of the format string. |
S |
Returns a leading or trailing minus sign (-) or plus sign (+), depending on whether the value is positive or negative. Can only be placed at the beginning or end of the format string. Eliminates the usual single leading space, but not leading spaces as the result of excess 9s, zeroes, or commas. |
$ |
Returns a leading dollar sign in front of the value. Can be placed anywhere in the format string. |
, |
Returns a comma in the specified position. If there are no digits to the left of the comma, the comma is replaced with a space. You can specify multiple commas, but cannot specify a comma as the first character in the format, or to the right of the decimal point. |
FM |
Strips leading spaces from the output. |
The following table shows several examples of format strings and the resulting output. Note that a space in the output is represented by a small circle (·):
Example |
Output |
---|---|
TO_STRING(1234,'9999') |
"·1234" |
TO_STRING(1234.567,'9999') |
"·1235" |
TO_STRING(1234.567,'999') |
"####" |
TO_STRING(1234.567,'9999D999') |
"·1234.567" |
TO_STRING(1234.567,'9999D9') |
"·1234.6" |
TO_STRING(1234.567,'9999.9999') |
"·1234.5670" |
TO_STRING(1234.567,'999999.9999') |
"···1234.5670" |
TO_STRING(1234.567,'009999.999') |
"·001234.567" |
TO_STRING(1234.567,'00000.999') |
"·01234.567" |
TO_STRING(1234.567,'9,999.999') |
"·1,234.567" |
TO_STRING(1234.567,'9,9,999.999') |
"···1,234.567" |
TO_STRING(1234.567,'FM9,9,999.999') |
"1,234.567" |
TO_STRING(1234.567,'$9,999.999') |
"·$1,234.567" |
TO_STRING(1234.567,'9,999.$999') |
"·$1,234.567" |
TO_STRING(1234.567,'EEEE') |
"1E+03" |
TO_STRING(1234.567,'.999EEEE') |
"1.235E+03" |
TO_STRING(1234.567,'999.999EEEE') |
"1.235E+03" |
TO_STRING(1234.567,'.99999999EEEE') |
"1.23456700E+03" |
TO_STRING(1234.567,'S9,999.99') |
"+1,234.57" |
TO_STRING(1234.567,'9,999.99S') |
"1,234.57+" |
TO_STRING(1234.567,'9,9,999.99S') |
"··1,234.57+" |
TO_STRING(1234.567,'FM9,9,999.99S') |
"1,234.57+" |
The following example converts a numeric value to a string:
INSERT INTO OutStream SELECT TO_STRING(Trades.Price) FROM Trades;
The following example converts a TIMESTAMP to a STRING with a format specifying precision:
INSERT INTO OutStream SELECT TO_STRING(Trades.TradeTime, 'YYYY-MM-DD HH:MI') FROM Trades;