Caché SQL Reference
STR


A function that converts a numeric to a string.
Synopsis
STR(number[,length[,decimals]])
Arguments
Description
STR converts a numeric to the STRING format, truncating the numeric based on the values of
length and
decimals. The
length argument must be large enough to include the entire integer portion of the number, and, if
decimals is specified, that number of decimal digits plus 1 (for the decimal point). If
length is not large enough,
STR returns a string of asterisks (*) equal to
length.
STR converts numerics to their
canonical form before string conversion. It therefore performs arithmetic operations, removes leading and trailing zeros and leading plus signs from numbers.
If the
number argument is
NULL,
STR returns NULL. If the
number argument is the empty string (''),
STR returns the empty string.
STRING retains whitespace.
Example
In the following Embedded SQL example,
STR converts numerics into a string:
&sql(SELECT STR(123),
STR(123,4),
STR(+00123.45,3),
STR(+00123.45,3,1),
STR(+00123.45,5,1)
INTO :v,:w,:x,:y,:z)
IF SQLCODE'=0 {
WRITE !,"Error code ",SQLCODE }
ELSE {
WRITE !,"Resulting STR:",v," string"
WRITE !,"Resulting STR:",w," string"
WRITE !,"Resulting STR:",x," string"
WRITE !,"Resulting STR:",y," string"
WRITE !,"Resulting STR:",z," string" }
The first
STR function returns a string consisting of 7 leading blanks and the number 123; the seven leading blanks are because the default string length is 10. The second
STR function returns the string “ 123”; note the leading blank needed to return a string of length 4. The third
STR function returns the string “123”; the numeric is put into canonical form, and
decimals defaults to 0. The fourth
STR function returns “***” because the string length is not long enough to encompass the entire number as specified; the number of asterisks indicates the string length. The fifth
STR function returns “123.4”; note that the
length must be 5 to include the decimal digit.
See Also