|
I created a stored procedure to calcuate the day you were born. I want it to throw an exception if the date is in the future or if the date is invalid such as a leap like February 30, 1977. i have included this logic but it is not throwing the exceptions. I have used sysdate to calculate aginst any future dayes as you will see below in the code. Any idea why I can't get the exceptions to work? I am using Oracle.
(comments are locked)
|
|
It looks like the line should cause the error when executing the to_date part because this function can only take valid looking dates. This means that the logic you have does not actually trap the e_invalid_day but still it should show you some error. I mean that if invalid date is passed then to_date fails and the code never gets to the line reading CASE v_dnum so the logic to trap invalid date input should be somewhat different, but I cannot see why the flow does not branch to the catch all WHEN OTHERS part. It does show an error that the date is not valid. But I want it to show my dbms_ouptut_line for e_invalid_day. I don't know why it is not showing that?
Oct 10 '11 at 04:52 PM
sqlnewb
@sqlnewb As I tried to explain in my comment above, the logic to raise invalid day is not correct. When the input date is invalid then there is simply no way for the flow to even get to the case statement let alone ( or should I say much less :) ) to the line reading ELSE RAISE e_invalid_day; because to_date() function does not allow garbage arguments. You can risk getting the invalid day message into the WHEN OTHERS clause, that is check for the v_error_code value and if it is consistent with the code for invalid argument of to_date() function then spell out DBMS_OUTPUT.PUT_LINE (CHR(10)||CHR(10)|| 'Invalid Day Calculated '||v_dnum); If not then spell out whatever you do in that WHEN OTHERS clause. You can also safely remove WHEN e_invalid_day as it will never happen for the flow to get there.
Oct 11 '11 at 08:20 AM
Oleg
(comments are locked)
|

