Purpose
You can call this function to convert 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 | (Optional) Specifies the output format. If you do not specify fmt, values of the datetime parameter will be converted to the VARCHAR2 data type:
|
| nlsparam | (Optional) Specifies the language used for the month and day returned. |
Return types
This function returns the data type of the national character set.
Examples
Use the
TO_NCHARfunction 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 setConvert a time interval value to the numeric format and set 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