Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: boolean in caluclations

Re: boolean in caluclations

From: <fitzjarrell_at_cox.net>
Date: 29 May 2007 13:45:09 -0700
Message-ID: <1180471508.959940.321140@p47g2000hsd.googlegroups.com>


On May 29, 2:40 pm, jobs <j..._at_webdos.com> wrote:
> how can i do this in pl-sql?
>
> when lines=2 that is replaced by a 1 allowing that math to take place
>
> when lines>2 it adds the other piece instead. Trying to avoid if
> statements.
>
> fee := (fixed_mf + ((lines=2)* lines_2) +
> (((lines>2)*(lines-1))*lines_more));
>
> thanks for any help or information.

You cannot rid yourself of 'if' statements in PL/SQL when dealing with booleans. You can, however, do this:

declare

     twolines boolean;
     morelines boolean;
     ...
begin
     ...
     twolines := lines = 2;
     morelines := lines > 2;

     if twolines then
          fee:=fixed_mf + lines_2;
     elsif morelines then
          fee:=(lines - 1)*lines_more;
     end if;

     ...

I believe that implements the logic you presented, albeit with the dreaded 'if' statements you so wanted to discard.

David Fitzjarrell Received on Tue May 29 2007 - 15:45:09 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US