Re: How to avoid divide by zero errors?
From: Adrian Billington <billiauk_at_yahoo.co.uk>
Date: 26 Mar 2002 00:49:01 -0800
Message-ID: <dee17a9f.0203260049.382b9235_at_posting.google.com>
Date: 26 Mar 2002 00:49:01 -0800
Message-ID: <dee17a9f.0203260049.382b9235_at_posting.google.com>
Use DECODE...
SELECT DECODE(column2,0,-1,column1/column2) AS my_calc FROM my_table;
If there's a chance of column2 being NULL, then:- SELECT DECODE(NVL(column2,0),0,-1,column1/column2) AS my_calc FROM my_table;
This is the cleanest way. Don't use the previous union example as this will require two scans of the table then a sort and merge...
Regards
Adrian Received on Tue Mar 26 2002 - 09:49:01 CET