Re: "IF" equivilent in SQL select?????

From: Sean McMurray <smcmurr_at_xmission.com>
Date: Fri, 07 May 1999 16:00:05 -0700
Message-ID: <37337075.A00A1B09_at_xmission.com>


Vickie Jones wrote:

> Is there a function(?) that would be the equivilent to an "IF" statment that
> can be used in a select statment? Below is a sample of what I am trying to
> do and the results:
>
> analyze index ccdbp.ALARMS_CODES_KEY validate structure;
> col key_name format A50
> select 'ALARMS_CODES_KEY' as key_name,del_lf_rows/lf_rows "Ratio" from
> index_stats;
>
> ERROR:
> ORA-01476: divisor is equal to zero
>
> What I need is an "if" statement that says if lf_rows is 0 (zero) set
> 'del_lf_rows/lf_rows' to 0 (zero). I want to eliminate this error when I
> analyze my indexes.
>
> Thanks in advance!
> Vickie Jones
> Republic Engineered Steels, Inc.
> Canton, OH

How about this:

select 'ALARMS_CODES_KEY' as key_name, decode(lf_rows, 0, 0, del_lf_rows)/decode(lf_rows, 0,1, lf_rows) as ratio from index_stats;

Does that work? Received on Sat May 08 1999 - 01:00:05 CEST

Original text of this message