Purpose
TO_NCHAR(datetime) converts a value of the DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE, INTERVAL YEAR TO MONTH, or INTERVAL DAY TO SECOND data type in the database character set to a data type in the national character set.
Syntax
TO_NCHAR({ datetime | interval }[, fmt [, 'nlsparam' ] ])
Parameters
| Parameter | Description |
|---|---|
| datetime | A value of the DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE, INTERVAL DAY TO SECOND, or INTERVAL YEAR TO MONTH data type. |
| interval | A value of the INTERVAL DAY TO SECOND or INTERVAL YEAR TO MONTH data type. The following interval units are supported:
|
| fmt | The format of the return value. This parameter is optional. If you do not specify fmt, the value of datetime is converted to a value of the VARCHAR2 data type in the following format:
|
| nlsparam | The language in which month and day names are returned. This parameter is optional. |
Return type
The return type is a data type of the national character set.
Examples
The following example uses the
TO_NCHAR()function to return the current date in theYYYY/MM/DDandDSDLformats respectively.obclient> SELECT TO_NCHAR(SYSDATE,'yyyy/mm/dd'),TO_NCHAR(SYSDATE,'DSDL') FROM DUAL; +--------------------------------+----------------------------------------+ | TO_NCHAR(SYSDATE,'YYYY/MM/DD') | TO_NCHAR(SYSDATE,'DSDL') | +--------------------------------+----------------------------------------+ | 2021/12/09 | 12/09/2021 Thursday, December 09, 2021 | +--------------------------------+----------------------------------------+ 1 row in setThe following example converts a time interval value to the numeric format and sets the language of the returned result to
AMERICAN.obclient> SELECT TO_NCHAR(interval'90' MINUTE, 'SS-MI-HH', 'nls_language = AMERICAN') FROM DUAL; +-----------------------------------------------------------------+ | TO_NCHAR(INTERVAL'90'MINUTE,'SS-MI-HH','NLS_LANGUAGE=AMERICAN') | +-----------------------------------------------------------------+ | +00 01:30:00 | +-----------------------------------------------------------------+ 1 row in set