Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 

 
 

ORA-01476 divisor is equal to zero tips

Oracle Error Tips by Burleson Consulting

 

Question: I?m using this query and it?s returning a divide by zero error:

SELECT
   STUSECMTAMT.totdebit/STUSECMTAMT.totalcr,
   STUJOURNAL.cre_bal/(STUSECMTAMT.totdebit/STUSECMTAMT.totalcr)
FROM
   STUSECMTAMT,STUDEG,STUJOURNAL
WHERE
   STUSECMTAMT.vhno=STUJOURNAL.ref_no
AND
   STUSECMTAMT.studegid=STUDEG.studegid;

ERROR at line 1:
ORA-01476: divisor is equal to zero

Can anyone shed a bit more light on how to detect and handle a divide by zero error? 

Answer: The Oracle oerr utility shows this on the divide by zero ORA-01476 error:

ORA-01476 divisor is equal to zero

Cause:
An expression attempted to divide by zero.

Action:
Correct the expression, then retry the operation.
 

You are dividing by 0.  In your case, either:

STUSECMTAMT.totalcr, (STUSECMTAMT.totdebit/STUSECMTAMT.totalcr)

 or

STUSECMTAMT.totalcr equates to 0.

You could use a decode or a case to capture the 0 and dtrap the condition without aborting the SQL.

Resolving divide by zero using DECODE

In the following example, a zero will be returned whenever the divisor is 0.

DECODE(STUSECMTAMT.totalcr,0,0,STUSECMTAMT.totdebit / STUSECMTAMT.totalcr)

Resolving divide by zero using CASE

You could also try a CASE statement.

CASE WHEN STUSECMTAMT.totalcr = 0 THEN 0 ELSE STUSECMTAMT.totdebit / STUSECMTAMT.totalcr END

Using zero_divide to handle a divide by zero error

In addition to using DECODE and CASE, another option is to trap the error in PL/SQL with the zero_divide option.  Just make a PL/SQL error exception to "trap" the ORA-01476 error with zero_divide

EXCEPTION
  WHEN ZERO_DIVIDE THEN
    DBMS_OUTPUT.put_line('Zero divide error - Try again);
END;

Or, you could replace the zero with small value (.000001) and computer the equation:

EXCEPTION
  WHEN ZERO_DIVIDE THEN
    :divisor_var := .000001;
END;

Lastly, you could replace the output of a divide by zero equation with a zero return value:

EXCEPTION
  WHEN ZERO_DIVIDE THEN
    return 0;
END;

 


 

 

��
 
 
 
 

 
 
 

 
Oracle performance tuning software 
 
oracle dba poster
Oracle Linux poster
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright ? 1996 -  2014

All rights reserved by Burleson

Oracle ? is the registered trademark of Oracle Corporation.