Re: DECODE .vs IF THEN ELSE (or ELSIF)
Date: 31 Mar 2004 06:25:40 -0800
Message-ID: <2687bb95.0403310625.6b07bf46_at_posting.google.com>
miotromailcarlos_at_netscape.net (Carlos) wrote in message news:<1de5ebe7.0403302353.775ce498_at_posting.google.com>...
> Moshe_t_at_yahoo.com (moshe) wrote in message news:<616be6f6.0403300906.34626f35_at_posting.google.com>...
> > Hello,
> >
> > I have simple function that get char value and according its value
> > return char value.
> > The function can looks like :
> > IF (InputValue = '00') THEN RETURN 'xxx'
> > ELSIF (InputValue = '01') THEN RETURN 'yyy'
> > ELSIF (InputValue = '02') THEN RETURN 'zzz'
> > and so on...
> >
> > Or I can use DECODE like :
> > Result := DECODE('00','xxx','01','yyy','02','zzz' .... )
> >
>
> NO, YOU CAN'T. DECODE can only be used inside a SQL statement.
>
> > My question is consider only to performance - What is the best way ?
> > Where I
> > will get the highest performance ?
> >
> >
> > Thanks.
>
> Martin Burbridge is completely right: don't try to outsmart the DB
> with hand-made functions and let the DB do what it does better.
>
> Regards.
>
> Carlos.
For that matter why not use the native SQL CASE statement?
SELECT CASE WHEN rownum > 07 THEN 'big time'
WHEN rownum < 04 THEN 'small fry' ELSE 'middle management' END as "CASE WHEN"FROM all_tables
WHERE rownum < 10 ;
HTH -- Mark D Powell -- Received on Wed Mar 31 2004 - 16:25:40 CEST