Solved

Oracle error - ORA-01476: divisor is equal to zero

Posted on 2014-11-29
3
3,102 Views
Last Modified: 2014-11-29
Hi

I'm having a problem with a section of my Query. This is probably because i have NULL fields. So it can't calculate properly.

Because of that, i have this error:

ORA-01476: divisor is equal to zero
01476. 00000 -  "divisor is equal to zero"
*Cause:    
*Action:

How can i fix this so that i just calculate what i can?

Thanks agauin




  case
    when STOP_TYPE = 'DL' and INBOUND = 'N' -- OB POs
    then  TO_CHAR((((TOTAL_MILES - TOTAL_IB_MILES)/TOTAL_MILES) * (ORDER_WEIGHT/TOTAL_OB_WEIGHT)*FREIGHT_COST),'9,999.99')
    when STOP_TYPE = 'DL' and INBOUND = 'I' -- IB POs
    then  TO_CHAR(((TOTAL_IB_MILES/TOTAL_MILES) * (ORDER_WEIGHT/TOTAL_IB_WEIGHT)*FREIGHT_COST),'9,999.99')
    when STOP_TYPE = 'DL' and TOTAL_ELAPSED_TIME < '000:00' -- LTL loads
    then  TO_CHAR(((ORDER_WEIGHT/TOTAL_WEIGHT)*FREIGHT_COST),'9,999.99')
    END AS PO_RATE_PRORATION

Open in new window

0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
dsacker earned 500 total points
ID: 40471861
It requires some sub-CASE statements to avoid the divide-by-zero error:
CASE
    WHEN STOP_TYPE = 'DL' AND INBOUND = 'N' THEN -- OB POs
        CASE
            WHEN TOTAL_MILES = 0 OR TOTAL_OB_WEIGHT = 0 THEN 0
            ELSE TO_CHAR((((TOTAL_MILES - TOTAL_IB_MILES)/TOTAL_MILES) * (ORDER_WEIGHT/TOTAL_OB_WEIGHT)*FREIGHT_COST),'9,999.99')
        END
    WHEN STOP_TYPE = 'DL' and INBOUND = 'I' THEN -- IB POs
        CASE
            WHEN TOTAL_MILES = 0 OR TOTAL_IB_WEIGHT = 0 THEN 0
            ELSE TO_CHAR(((TOTAL_IB_MILES/TOTAL_MILES) * (ORDER_WEIGHT/TOTAL_IB_WEIGHT)*FREIGHT_COST),'9,999.99')
        END
    WHEN STOP_TYPE = 'DL' and TOTAL_ELAPSED_TIME < '000:00' THEN -- LTL loads
        CASE
            WHEN TOTAL_WEIGHT = 0 THEN 0
            ELSE TO_CHAR(((ORDER_WEIGHT/TOTAL_WEIGHT)*FREIGHT_COST),'9,999.99')
        END
END AS PO_RATE_PRORATION

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40471867
Hi dsacker

Thanks, this is great. Now it works.
0
 
LVL 20

Expert Comment

by:dsacker
ID: 40471868
Awesome. Glad that helped.
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to recover a database from a user managed backup

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question