Purpose
This function converts the values of the DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE, INTERVAL YEAR TO MONTH, and INTERVAL DAY TO SECOND data types from the database character set to the national character set.
Syntax
TO_NCHAR({ datetime | interval }[, fmt [, 'nlsparam' ] ])
Parameters
Parameter |
Description |
|---|---|
| datetime | The value of the DATE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH LOCAL TIME ZONE, INTERVAL DAY TO SECOND, and INTERVAL YEAR TO MONTH data types. |
| interval | The value of the INTERVAL DAY TO SECOND and INTERVAL YEAR TO MONTH data types. The interval units are as follows:
|
| fmt | The output format. This parameter is optional. If you do not specify the fmt parameter, the value of the datetime parameter is converted to the VARCHAR2 data type in the following format:
|
| nlsparam | The language used for the returned month and day names. This parameter is optional. |
Return type
The national character set.
Examples
Use the
TO_NCHARfunction to return the current date in theYYYY/MM/DDandDSDLformats.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 setConvert the interval value to a numeric interval value and set the return language 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
