SQL/MX 3.1 Reference Manual (H06.23+, J06.12+)

SQL/MX Functions and Expressions
HP NonStop SQL/MX Release 3.1 Reference Manual663850-001
9-176
TO_CHAR(<NUMERIC>) Function
TO_CHAR(<NUMERIC>) Function
The TO_CHAR(<numeric>)function converts numeric data to formatted string. The
result string is VARCHAR type.
The following is the function syntax:
numeric-expression
is an SQL numeric value expression. Numeric data type can be NUMERIC(P,S),
SMALLINT, INT[EGER], LARGEINT, DEC[IMAL], REAL, FLOAT, or DOUBLE
PRECISION. NULL or dynamic parameter cannot be used as numeric-
expressions.
format-value
is a constant string that defines the output format. NULL, column name, expression, or
dynamic parameter cannot be defined as format-value. The following table lists all
the numeric elements that can be used to construct the numeric format-value.
TO_CHAR(numeric-expression, format-value)
Element Description
numeric-
expressi
on
format-
value Output
9 Specifies the number of digits in
the output format.
1234 9999 ‘ 1234’
0 Returns the value with leading
zeroes.
1 0999 ‘ 0001’
.(period)
D
Specifies the position of the
decimal point in the output
format.
Restriction: A decimal point can
occur only once within a format-
value.
12.34 99.99
99D99
‘ 12.34’
‘ 12.34’
,(comma)
G
Returns ‘,’ in the specified
position.
Restriction: You cannot specify
this element at the beginning or
after the decimal point.
1234 9,999
9G99
‘ 1,234’
‘ 1,234’
$ Returns a leading dollar sign.
Restriction: If you specify the
dollar sign at any position in the
format-value, the output
displays a leading $ sign.
1234 $9999 ‘ $1234’