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: DECODE question

Re: DECODE question

From: Tim Cross <tcross_at_nospam.une.edu.au>
Date: 13 Nov 2002 09:39:08 +1100
Message-ID: <878yzy76r7.fsf@blind-bat.une.edu.au>


jbatista_at_abcsolutions.org (Josue Batista) writes:

> Given the following two columns:
>
> ACCTD_AMOUNT_DUE_REMAINING NOT NULL NUMBER
> AMOUNT_DUE_REMAINING NOT NULL NUMBER
>
> What does the following statement mean?
>
> sum(decode(NULL,'Y',acctd_amount_due_remaining,amount_due_remaining))
>

I'll go out on a limb....

TO me this looks like a very silly bit of SQL to me.

The decode statement is similar to an if statement and could be translated as

if 1st arg = 2nd arg

   return 3rd arg
else

   return 4th arg

which in turn translates to

if NULL = 'Y'

   return acctd_amount_due_remaining
else

   return amount_due_remaining

since NULL never equals anything, this decode will always return amount_due_remaining. So, I tink the whole statement is equal to

sum(amount_due_remaining)

Maybe there is something missing like

sum(decode(nvl(sum_flag_value, 'N'),'Y', acctd_amount_due_remaining, amount_due_remaining));

Tim Received on Tue Nov 12 2002 - 16:39:08 CST

Original text of this message

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