Oracle TO_CHAR() Syntax Guide
TO_CHAR() is a function specific to Oracle databases. It is used to convert date, number, or string data types into a specified format of string.
The syntax of the TO_CHAR() function in Oracle is as follows:
TO_CHAR(value, format)
- The value is the value to be converted, which can be a date, number, or string.
- Format is a template used to specify the format in which values are converted to strings.
The TO_CHAR() function is commonly used for the following purposes:
- Convert the date into a specific format string, such as converting the date into “YYYY-MM-DD” format.
- Convert numbers into strings with specified precision and format, such as adding currency symbols or thousand separators.
- Display the string in the specified format.
For example, here is an example of converting a date to a string using the TO_CHAR() function:
SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD') AS formatted_date
FROM dual;
The above query will convert the current date into a string in the format of “YYYY-MM-DD” and return the result.