Returning values depending on data in column

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.

If Col2 is NOT NULL THEN 1
Else 0 NewColName,
From Database.
Who is Participating?
sdstuberConnect With a Mentor Commented:
the NVL2 function does exactly the if null else check

Select col1, nvl2(col2,1,0) from table;
slightwv (䄆 Netminder) Commented:
Select col1, case when col2 is not null then 1 else 0 end mycol from table;
SharathData EngineerCommented:
Select col1, decode(col2,null,0,1) mycol from table;
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

slightwv (䄆 Netminder) Commented:
Decode is still valid but is being phased out.
TechMonsterAuthor Commented:
This is the solution I used...thanks
why the B?  that's a penalty grade,  what more did you want for an A?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.