TO CHAR

From Oracle FAQ
Jump to: navigation, search

TO_CHAR is a SQL function that is used to convert a NUMBER or DATE value to a string.

[edit] Syntax

The syntax for the TO_CHAR function is:

to_char( value, [ format_mask ], [ nls_language ] )

Where:

  • value can either be a number or date that will be converted to a string.
  • format_mask is optional. This is the format that will be used to convert value to a string.
  • nls_language is also optional. This is the NLS language (regional settings) used to convert the value to a string.

[edit] Examples

Convert a number to a string:

SQL> SELECT TO_CHAR(1234, '$999G999G999') FROM dual;
TO_CHAR(1234,
-------------
       $1,234

Convert a date to a string:

SQL> SELECT TO_CHAR(SYSDATE, 'DD Month YYYY HH24:MI:SS') FROM dual;
TO_CHAR(SYSDATE,'DDMONTHYY
--------------------------
06 January   2009 09:18:38

[edit] Also see

  • TO_DATE, function to convert a string to a date.
  • TO_NUMBER, function to convert a string to a number.