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;
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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.