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!

How to return a text response using DECODE or CASE when "0 results"?

user10900672Feb 19 2010 — edited Feb 19 2010
I am trying to return a simple response, either 'Yes' or 'No' (in Oracle 9i), via two different SQL queries:

Here is my data:

schema.table1 a
user_iD-------privilege
1--------------2

schema.table2 c
user_id-----username
1------------JOE
2------------JAMES

Here are my queries:

SELECT DECODE (c.username,'JOE','YES','NO') BID_PRIV
FROM schema.table1 a, schema.table2 c
WHERE a.privilege = 2
AND a.user_id = c.user_id
and c.USERNAME = 'JOE';

SELECT DECODE (c.username,'JAMES','YES','NO') BID_PRIV
FROM schema.table1 a, schema.table2 c
WHERE a.privilege = 2
AND a.user_id = c.user_id
and c.USERNAME = 'JAMES';

The first query returns a YES. The second query returns 0 results, since JAMES does not have Privilege = 2 (he has no records in that schema.table1). I want the second query to return a 'NO'. I've tried using a NULL, but that didn't work.

I also tried CASE but that too seems to have a problem when you get No Results.

Any ideas?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 19 2010
Added on Feb 19 2010
4 comments
924 views