SQL Provides 3 functions to convert a value from one data type to another:
TO_CHAR (number | date, [, fmt] )
This function converts a number or date value to a VARCHAR2 character string with format model fmt.
TO_NUMBER (char, [fmt] )
This function converts a character string containing digits to a number in the format specified by the optional format model fmt.
TO_DATE (char, [fmt] )
This function converts a character string representing a date to a date according to the fmt specified. If fmt is omitted, the format is DD-MON-YY.
TO_CHAR (number | date, [, fmt] )
This function converts a number or date value to a VARCHAR2 character string with format model fmt.
TO_NUMBER (char, [fmt] )
This function converts a character string containing digits to a number in the format specified by the optional format model fmt.
TO_DATE (char, [fmt] )
This function converts a character string representing a date to a date according to the fmt specified. If fmt is omitted, the format is DD-MON-YY.
Using the TO_CHAR Function with Dates
TO_CHAR(date,'format_model')
The format model:
- Must be enclosed in single quotation marks and is case sensitive.
- Can include any valid date format element.
Example:
TO_CHAR ( number,'format_model')
Example: here you can notice the both sal and salary printed with formatted result.
Note:
TO_NUMBER()
and TO_DATE()
I'll upload the example if any one ask for me. In the comment section ask for me, and I'll upload it.
No comments:
Post a Comment