The to_char() function is used to convert date to character. You can also specify the format in which you want output.
SELECT to_char ( to_date (’12-12-2012′, ‘DD-MM-YYYY’) , ‘YYYY-MM-DD’) FROM dual;
Or,
SELECT to_char ( to_date (’12-12-2012′, ‘DD-MM-YYYY’) , ‘DD-MM-YYYY’) FROM dual;
In Oracle, you can use the TO_CHAR
function to convert a date to a character string. The syntax is as follows:
TO_CHAR(date_value, 'format_mask')
Here, date_value
is the date you want to convert, and format_mask
is the format in which you want to display the date.
For example, if you want to convert the current date to a string in the format ‘YYYY-MM-DD’, you can use the following query:
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD') FROM DUAL;
In this example, SYSDATE
is the current date and time function, and ‘YYYY-MM-DD’ is the desired format. The FROM DUAL
part is used in Oracle to select a constant value when no actual table is involved in the query.