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

Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle Magazine Blooper

Re: Oracle Magazine Blooper

From: Brian Peasland <dba_at_remove_spam.peasland.com>
Date: Mon, 10 May 2004 20:06:25 GMT
Message-ID: <409FE0C1.DBD4FF1C@remove_spam.peasland.com>


FlameDance wrote:
>
> Brian Peasland wrote:
>
> >>And for anyone interested in a possibly more reasonable approach:
> >>
> >>SELECT parameter,
> >>CASE WHEN parameter < 1000 THEN 'C' ELSE 'P' END AS BAND
> >>FROM parameter_table;
>
> Nice and precice.
>
> > SELECT parameter,DECODE(SIGN(parameter-1000),-1,'C','P') AS band
> > FROM parameter_table;
> >
>
> I hate DECODE with a passion. It's like C: short, fast - and unreadable.
> Rather than this I'll have the much scowled at original (after cleaning
> up the two RETURN statements), at least I know at 1 glance what it does.
>
> Stephan

I couldn't agree with you more. However, the CASE function is not available in all Oracle versions. And that's exactly why I said "And for those who don't have CASE". If you have CASE available to you, the go ahead and use it. If you don't have CASE available to you, then you can use the DECODE statement above.

One point that should be noted is that if this code will be used repeatedly, then a FUNCTION might be the way to go. Rather than code DECODE or CASE over and over again in various SELECT statements, a call to a function just might be in order. Although most would probably consider this a trivial exercise.

Cheers,
Brian


Brian Peasland
dba_at_remove_spam.peasland.com

Remove the "remove_spam." from the email address to email me.

"I can give it to you cheap, quick, and good. Now pick two out of  the three" Received on Mon May 10 2004 - 15:06:25 CDT

Original text of this message

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