Home » SQL & PL/SQL » SQL & PL/SQL » Yes/No in columns (Oracle SQL*Plus, Oracle 10g)
Yes/No in columns [message #298300] Tue, 05 February 2008 10:53 Go to next message
drkeith
Messages: 2
Registered: February 2008
Junior Member
Quick question for a Oracle/SQL noob. I have a column which has some values and some null values. If there is a number in the column I want to put a "Yes" in my report, but if it is null, I would like a "no" in there.

Can anyone offer any help? I'm pulling my hair out over this.

Thanks!

Re: Yes/No in columns [message #298303 is a reply to message #298300] Tue, 05 February 2008 10:57 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Check the docs (or google) for DECODE
Re: Yes/No in columns [message #298309 is a reply to message #298303] Tue, 05 February 2008 11:42 Go to previous messageGo to next message
pablolee
Messages: 2835
Registered: May 2007
Location: Scotland
Senior Member
Or NVL2
Re: Yes/No in columns [message #298329 is a reply to message #298300] Tue, 05 February 2008 13:20 Go to previous messageGo to next message
Bill B
Messages: 1484
Registered: December 2004
Senior Member
decode(my_column,null,'NO','YES')
Re: Yes/No in columns [message #298383 is a reply to message #298329] Wed, 06 February 2008 00:11 Go to previous message
Littlefoot
Messages: 20901
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
... or even CASE (I hope there's some hair left)
SQL> select flag,
  2    case when flag is null then 'No'
  3         else 'Yes'
  4    end r_1,
  5    decode(flag, null, 'No', 'Yes') r_2,
  6    nvl2(flag, 'Yes', 'No') r_3
  7  from test;

F R_1 R_2 R_3
- --- --- ---
  No  No  No
F Yes Yes Yes
  No  No  No
V Yes Yes Yes
V Yes Yes Yes

SQL>
Previous Topic: Encountered the symbol "end-of-file" when expecting one of the following:
Next Topic: memory allocation of associative arrays
Goto Forum:
  


Current Time: Fri Dec 09 00:21:51 CST 2016

Total time taken to generate the page: 0.12014 seconds