I got ” ORA-01847: day of month must be between 1 and last day of month ” error in Oracle database.
ORA-01847: day of month must be between 1 and last day of month
Details of error are as follows.
ORA-01847 day of month must be between 1 and last day of month Cause: The day of the month listed in a date is invalid for the specified month. The day of the month (DD) must be between 1 and the number of days in that month. Action: Enter a valid day value for the specified month.
SELECT TO_DATE('2021/04/31', 'yyyy/mm/dd') FROM dual;
day of month must be between 1 and last day of month
This ORA-01847 error is related with the day of the month listed in a date is invalid for the specified month.
The day of the month (DD) must be between 1 and the number of days in that month.
Enter a valid day value for the specified month.
If you run the following code, you will get this error.
SELECT TO_DATE('2021/04/31', 'yyyy/mm/dd') FROM dual; SELECT TO_DATE('2020/12/32', 'yyyy/mm/dd') FROM dual;
Because There is no 31 day in the April, and 32 day in December, Last day is 30 in April and 31 is in December, so you need to use it as follows.
SELECT TO_DATE('2021/04/30', 'yyyy/mm/dd') FROM dual; SELECT TO_DATE('2020/12/31', 'yyyy/mm/dd') FROM dual;
You can read the following post to learn more details about TO_DATE Function.
Do you want to learn Oracle Database for Beginners, then read the following articles.
Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )