Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Oracle 8i SQL Statement
"Kent Prokopy" <kent_prokopy_at_stream.com> wrote in message
news:ec8c1578.0309190353.28346e7d_at_posting.google.com...
> When using the DECODE function, is there any way of passing it the
> IN() clause?
>
> Example:
> DECODE(FIELDNAME,IN(1,2,3),TRUE,FALSE)
>
> This returnning TRUE if the values of 1, 2 or 3 are found. So far the
> only way I can get this to work is as follows:
>
> DECODE(FIELDNAME,1,TRUE,2,TRUE,3,TRUE,FALSE) "This leaving a lot of
> room for typo errors."
>
> Thank you.
> Kent Prokopy
Try it and see what happens.
NOTE that you can only use boolean values in PL/SQL not SQL if recall.
SQL> select decode(1, in (1,2,3), 'FALSE', 'TRUE')
2 from dual
3 /
select decode(1, in (1,2,3), 'FALSE', 'TRUE')
*
Elapsed: 00:00:00.00
SQL>
As you can see that it doesn't work. Use this instead :
SQL> select (case when 1 in (1,2,3) then
2 'TRUE' 3 else 4 'FALSE' 5 end ) as results
RESUL
2 'TRUE' 3 else 4 'FALSE' 5 end ) as results
RESUL
-- \|/ o o __________________________________oOO_(_)_OOo______________________________ E-Business and Information Management | God said ... Knowledge Discovery & Dissemination | 1. div D = p onismusr-AT-absa-DOT-co-DOT-za | 2. curl E = -dB/dt Tel: +27 11 350 3414 | 3. div B = 0 Fax: +27 11 350 8585 | 4. curl H = dD/dt + J Cel: +27 83 591 5310 | ... and there was light. ___________________________________________________________________________Received on Fri Sep 19 2003 - 08:04:45 CDT
![]() |
![]() |