TO_CHAR

The TO_CHAR function converts a DATE, TIMESTAMP or numeric input value to a VARCHAR2.

SQL syntax

TO_CHAR ( Expression1[, Expression2 [, Expression3]])

Parameters

TO_CHAR has the parameters:

Parameter Description

Expression1

A DATE, TIMESTAMP, CLOB, NCLOB, or numeric expression.

Expression2

The format string. If omitted, TimesTen uses the default date format (YYYY-MM-DD).

Expression3

A CHAR or VARCHAR2 expression to specify the NLS parameter, which is currently ignored.

Description

  • TO_CHAR supports different datetime format models depending on the data type specified for the expression. See "Datetime Format Models" for information on the datetime format model used for TO_CHAR of data type DATE or TIMESTAMP. See "Format Model for ROUND and TRUNC Date Functions" for information on the datetime format model used for TO_CHAR of data type TT_DATE or TT_TIMESTAMP.

  • TO_CHAR supports different number format models depending on the numeric data type specified for the expression. See "Number Format Models" for information on the number format model used for TO_CHAR of data type NUMBER or ORA_FLOAT. See "Format Model for ROUND and TRUNC Date Functions" for information on the number format model used for TO_CHAR of all other numeric data types.

Examples

SELECT FIRST 5 first_name, 
               TO_CHAR (hire_date, 'MONTH DD, YYYY'),
               TO_CHAR (salary, '$999999.99')
  FROM employees;
< Steven, JUNE      17, 1987,   $24000.00 >
< Neena, SEPTEMBER 21, 1989,   $17000.00 >
< Lex, JANUARY   13, 1993,   $17000.00 >
< Alexander, JANUARY   03, 1990,    $9000.00 >
< Bruce, MAY       21, 1991,    $6000.00 >
5 rows found.

SELECT TO_CHAR(-0.12,'$B99.9999') FROM dual;
<   -$.1200 >
1 row found.

SELECT TO_CHAR(-12, 'B99999PR') FROM dual;
<     12  >
1 row found.

SELECT TO_CHAR(-12,'FM99999') FROM dual;
< -12 >
1 row found.

SELECT TO_CHAR(1234.1,'9,999.999') FROM dual;
<  1,234.100 >
1 row found.