If I have a date format DDMM
in PL/SQL and I want to validate it. What is the correct way to do it?
DD
is the day and MM
is th
to_date
raises an exception if its input parameter is not a valid date. So you can do something like:
declare
x date;
begin
x := to_date('3210', 'DDMM'); -- Will raise ORA-1847
x := to_date('0113', 'DDMM'); -- Will raise ORA-1843
exception
when others then
if sqlcode in (-1843, -1847) then
dbms_output.put_line('Invalid Date!');
null;
else
raise;
end if;
end;