Solved

Returning values depending on data in column

Posted on 2011-02-11
6
407 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 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 40

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
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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle query output question 4 48
Can anyone please tell me what does below Stored Procedure does? 4 33
Help on model clause 5 37
oracle date format checking 7 26
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…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
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 copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

829 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