Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Question about returning value if no rows return

Ebiru2387Mar 3 2020 — edited Mar 4 2020

Hi all,

I am trying to run a query where i have  50+ values i need to search for.  However if lets say only 45 of these return, i have to go fishing for the other 5 to find out which ones didn't return.  Therefore i am trying to find a way to have a pre-determined value return for these 5 remaining rows. For example the below is a simple bit of code i need to run.

SELECT *

FROM

TABLE_NAME

WHERE COL_NAME IN ('Val1' ,'Val2' , 'Val3');

In the above example let us say only Val1 and Val2 return.  This means no data will return for Val3. This is simple with 3 values as i can see which is missing, but if i have 50 or more this becomes time consuming.  Is there a way i can create a new column that would say "Present" for values that do return, and "Not Present" for values that don't?   I was considering using a CASE clause, but i only know how to make this work to a certain extent, and not for the purposes of this post.

I am fairly new to SQL, and i imagine there are more efficient ways to go about what i am doing.  So i appreciate your patience if i am asking stupid questions or not using the correct terminology.  I have searched the internet for this, and while i found some solutions that get me partly there, i haven't found anything that meets my needs.

Kind Regards,

Comments
Post Details
Added on Mar 3 2020
6 comments
10,079 views