x

Divided by 0 exception error?

We created a procedure, where there is a formula as follows.

Count:=Avl/cnter

Here some times the cnter value is coming 0. So the procedure is throughing an exception. How can we handle this error in pl/sql procedure?

more ▼

asked Dec 09, 2009 at 07:04 PM in Default

dbkid gravatar image

dbkid
131 9 10 11

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You could avoid the error altogether, don't divide when 0, just return a 0 (or some other value):

count = case when cntr <> 0 then avl/cntr else 0 end 
more ▼

answered Dec 10, 2009 at 02:33 AM

KillerDBA gravatar image

KillerDBA
1.5k 8 9 10

Yep KillerDBA. This case statement solved the eror. Thank you.
Dec 10, 2009 at 09:19 PM dbkid
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x50

asked: Dec 09, 2009 at 07:04 PM

Seen: 575 times

Last Updated: Dec 09, 2009 at 07:04 PM