Solved

Returning values depending on data in column

Posted on 2011-02-11
6
406 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
6 Comments
 
LVL 76

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 40

Expert Comment

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

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34875948
Decode is still valid but is being phased out.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 73

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 73

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

809 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