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* to implement IF condition???

Re: *DECODE* to implement IF condition???

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Wed, 31 Oct 2001 09:53:43 -0000
Message-ID: <1004522255.6545.0.nnrp-01.9e984b29@news.demon.co.uk>

You need to state an Oracle version to get the best answer to this question. For 8.1.6+ the answer supplied by Richard is the smart
strategy (although I would have used a CASE within a CASE and dropped the DECODE()
completely).

If you want to run this inside PL/SQL, though, it will be rejected unless you take the extra step of using dynamic SQL - look at the
'execute immediate' command.

On earlier versions of Oracle, this usually turns into a messy sequence of subtracting sysdate and decoding the sign() function applied to the result.

--
Jonathan Lewis
http://www.jlcomp.demon.co.uk

Host to The Co-Operative Oracle Users' FAQ
http://www.jlcomp.demon.co.uk/faq/ind_faq.html

Author of:
Practical Oracle 8i: Building Efficient Databases

Screen saver or Life saver: http://www.ud.com
Use spare CPU to assist in cancer research.

Vamshi wrote in message ...

>HI All,
>I have a conditional display situation as below:
>
>if T1.Col4 = 'ABC'
>{ if ( (T1.date1 < sysadate) && (T1.date2 > sysdate) )
> { DISPLAY 'ABC YES';
> }
> else
> { DISPLAY 'ABC NO';
> }
>}
>else if T1.Col4 = 'DEF'
>{ if ( (T1.date1 < sysadate) && (T1.date2 > sysdate) )
> { DISPLAY 'DEF YES';
> }
> else
> { DISPLAY 'DEF NO';
> }
>}
>else
>{ DISPLAY "NEITHER ABC NOR DEF"
>}
>
>Can this condition be implemented in a select statement with DECODE...
>that looks like
>
>****************************************
>Select decode(.....some smart logic.....)
>from table T1
>****************************************
>
>Any clues on how to approach this?
>
>Thanks folks!
>
>Cheers,
>Vamshi Reddy
Received on Wed Oct 31 2001 - 03:53:43 CST

Original text of this message

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