Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Date format error handling

sadasivamJul 26 2019 — edited Jul 26 2019

Hi,

I an getting date in varchar2 field with different format like,

28-02-2019,28022019,28FEB2019,28-FEB-2019

for converting this into date FIELD i am using to_date function and it is fine if the date is valid.

SELECT To_Date('28022019','DD-MM-YYYY') FROM DUAL

but for each format i will get different error message if the date is not valid.

SELECT To_Date('31022019','DD-MM-YYYY') FROM DUAL

ORA-01861: literal does not match format string

SELECT To_Date('31-02-2019','DD-MM-YYYY') FROM DUAL

ORA-01839: date not valid for month specified

SELECT To_Date('31-FEB-2019','DD-MM-YYYY') FROM DUAL

ORA-01858: a non-numeric character was found where a numeric was expected

Client expecting the valid standard message .Is it possible to apply some logic to get the standard error message like "day of month must be between 1 and last day of month" for any formats with the date is not valid for that month.

Thanks.

Comments
Post Details
Added on Jul 26 2019
10 comments
8,474 views