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!

Handle divide by zero error in SQL

user11440683Oct 11 2010 — edited Oct 11 2010
Hi,


a few posts back someone asked the best way to handle divide by zero.

Can I revisit this theme with, what is the best way to handle divide by error in SQL without repeating code...

What I have in mind is quite frequently divided by error appears as the result of a lengthy formula calculation - and trying to burying a lengthy a lengthy formula calculation in a case statement gives you an exceedingly long result, which is not great for code maintenance.

Wrapping the handling in a function is also not great for reasons of performance.


So is there any simple way to do the equivalent of (pseudo code)


select IFerr( actual / (RidiculouslyLongConvulutedFormulaHereWhichSometimesYieldsZeroValues), 0) from dual

Where IFerr works like NVL - except it yields 0 when the result is a number error, or the result otherwise?



thanks,

Robert.
This post has been answered by odie_63 on Oct 11 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 8 2010
Added on Oct 11 2010
5 comments
47,089 views