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 if else statement

Re: oracle if else statement

From: IM <ian_at_ianmurphy.freeserve.co.uk>
Date: Wed, 06 Jun 2007 08:46:38 -0700
Message-ID: <1181144798.348054.236080@p77g2000hsh.googlegroups.com>


On Jun 6, 10:43 am, odelya <be.spec..._at_gmail.com> wrote:
> Hi!
> I would like to write a statement using if/else for example:
> select *from table
> if value!= null then
> where value = table.value
> end if
>
> value = will be a string which might be null.
>
> im using oracle 9i

Use CASE.

SELECT <column1>, CASE
  WHEN <column1> = <condition1> THEN <result1>
  WHEN <column1> = <condition2> THEN <result2>
  WHEN NULL THEN 'BOB'
  ELSE <alternate result>
  END <identifier>

<column1> IDENTIFIER

---------------- -----------------

condition1 result1
condition2 result2
condition3 alternate result
condition4 alternate result
                 BOB

--
HTH

Ian
Received on Wed Jun 06 2007 - 10:46:38 CDT

Original text of this message

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