My query is
select TO_CHAR('03-JAN-2013', 'D') from dual;
but an error occured as
ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause:
*Action:
But when query changed as select TO_CHAR(sysdate, 'D') from dual;
Result is right answer 5.
I can't understand why it is behaving like this, please help me.
Thanks in advance
SELECT customer_id, TO_CHAR(dob, 'MONTH DD, YYYY') FROM customers; The next query gets the current date and time from the database using the SYSDATE function, then converts the date and time to a string using TO_CHAR() with the format MONTH DD, YYYY, HH24:MI:SS.
To_char formats a DATE into a string using the given format mask. To_date converts a STRING into a date using the format mask.
Use TO_CHAR to display it in any format you like. For example: SELECT TO_CHAR ( TO_DATE (date_value, 'yyyy-mm-dd') , 'mm/dd/yyyy' ) FROM table_x; Things are much easier if you store dates in DATE columns.
In Oracle, TO_CHAR function converts a datetime value (DATE, TIMESTAMP data types i.e.) to a string using the specified format. In SQL Server, you can use CONVERT or CAST functions to convert a datetime value (DATETIME, DATETIME2 data types i.e.) to a string.
Please cast the string to date before selecting.
SELECT TO_CHAR(CAST('03-JAN-2013' AS DATE), 'D') FROM DUAL;
OR
SELECT TO_CHAR(TO_DATE('03-JAN-2013'), 'D') FROM DUAL;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With