Solved

Returning values depending on data in column

Posted on 2011-02-11
6
414 Views
Last Modified: 2012-05-11
I have a query in oracle..looking at returning a numeric value of 1 if a column is not NULL and 0.
some folks said that it would be similar to SQL but my query doesn't work.

So the value I want to change is Col2.  Set to 1 if the there is anything in Col2, and 0 if it is NULL.

Select
Col1,
If Col2 is NOT NULL THEN 1
Else 0 NewColName,
Col3,
From Database.
0
Comment
Question by:TechMonster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34875838
Select col1, case when col2 is not null then 1 else 0 end mycol from table;
0
 
LVL 41

Expert Comment

by:Sharath
ID: 34875941
Select col1, decode(col2,null,0,1) mycol from table;
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34875948
Decode is still valid but is being phased out.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 34876677
the NVL2 function does exactly the if null else check

Select col1, nvl2(col2,1,0) from table;
0
 

Author Closing Comment

by:TechMonster
ID: 34876851
This is the solution I used...thanks
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 34876931
why the B?  that's a penalty grade,  what more did you want for an A?
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question