STR() Function - Numeric to String and String Masking

Syntax

STRING(num{,mask})
STRING(string{,mask})

Description

The first STR() function above returns an ASCII string representing the value of its numeric argument. The result can be formatted using the optional string mask.

The NUM() function is complementary to the STR() function when the STR() function is used without a mask that places non-numeric characters in the result.

The STR() function STR(string{,mask}) returns its string argument applied to the specified mask. The specified positions in the mask will be filled with successive characters from the string. The following characters in the mask will be replaced by characters from the string:

Mask

Character(s) Replaced

X

Any printable character

A

Any alphabetic character and converts to upper case

a

Any alphabetic character

0

Any digit

Z

Any digit or alphabetic character and converts to upper case

z

v digit or alphabetic character

Any other character in the mask simply represents itself. If a character type mismatch occurs, such as trying to place a "W" into a mask position designated for a digit, an error is generated. If the source string is too short, spaces are used to pad the remainder of the mask. If the source string is too long, an error is generated.

Example

Select STR(CURR_BAL,'$###,##0.00') from Customer