Home » SQL & PL/SQL » SQL & PL/SQL » DECODE explanation
DECODE explanation [message #2692] Tue, 06 August 2002 19:31 Go to next message
weeang
Messages: 1
Registered: August 2002
Junior Member
Hi,

I need someone to explain to me exactly what is happening for the following DECODE statement:

"sum(decode(ltrim(a),'01',0,'02',0,'03',0,'04',0,'05',0,'06',0,'07',0,'08',0,to_number(b)*c))"

I actually understand the following DECODE statement as:
"sum(decode(ltrim(a),'08',b*c,0))"

if ltrim(a) = '08' then b*c else 0

Not sure if I got things right or not, but would really appreciate help on this.

Thanks and Brgds, weeang
Re: DECODE explanation [message #2707 is a reply to message #2692] Wed, 07 August 2002 09:31 Go to previous messageGo to next message
MikeT
Messages: 11
Registered: August 2002
Junior Member
Seems like you've got it right. Basically, it returns 0 for values '01' thru '08'. For everything else it returns "to_number(b)*c".
Re: DECODE explanation [message #2712 is a reply to message #2692] Wed, 07 August 2002 11:41 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Mike's explanation of the intent of the first statement is correct, however your translation is not a match for the logic.

The first statement returns 0 for ltrim(a) values of '01'-'08', and (to_number(b)*c) for all other values.

Your translation return (b*c) for ONLY '08', and 0 for everything else. This is not the same at all.
Previous Topic: Can I use a PL/SQL function in a SQL SELECT statement
Next Topic: Delete statement
Goto Forum:
  


Current Time: Fri Mar 29 10:41:52 CDT 2024