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: Easy DECODE query (hopefully)...

Re: Easy DECODE query (hopefully)...

From: fumi <fumi_at_tpts5.seed.net.tw>
Date: 13 Mar 2000 17:27:06 GMT
Message-ID: <8aj8da$h5$1@news.seed.net.tw>

<dolans_at_my-deja.com> wrote in message news:8aiv29$rku$1_at_nnrp1.deja.com...
> I have a table:
> FOO
> -------
> ID
> THE_VALUE
>
> If I do a :
> "Select decode(id, NULL, 0, 1) from FOO where THE_VALUE='Mom';"
>
> I get no rows selected. I would like it to return 0 if there is no
> entry in the table for 'Mom'.
>
> Is NULL the correct expression? Yes, I could use count(Id) in the
> search expression instead, but I am trying to return the ID if it
> exists or 0 if it doesn't.

Yes. It needs some trick:
(On PO8.0.4 & Windows 98)

SQL> create table foo (id number, the_value varchar2(8));

Table created.

SQL> select decode(id, null, 0, 1)
  2 from foo, (select 'Mon' criterion from dual)   3 where the_value(+)=criterion;

DECODE(ID,NULL,0,1)


                  0






Received on Mon Mar 13 2000 - 11:27:06 CST

Original text of this message

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