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!

return empty record only when no results are returned from main query

744011Jul 7 2010 — edited Jul 8 2010
This is a SQL (not PL/SQL) question...

Let's say I have the following:

SELECT NULL full_name, NULL address, NULL last_update_date
FROM dual
UNION ALL
SELECT full_name, address, last_update_date
FROM employees
WHERE TRUNC(sysdate)=TRUNC(last_update_date)

If the second part of the query retrieves no rows, this works wonderfully and I get an empty row; however, if the second part of the query returns records, I will get an empty row plus my dataset that I want.

How can I create a SQL statement that would only execute the first query (before the union all) when no results are returned from the second. Also, I don't want to exceute the query twice just so I can get a count of the records because my actual query is much more complex than the example I've provided here.

Thanks in advance!
Emily
This post has been answered by kordirko on Jul 7 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 5 2010
Added on Jul 7 2010
9 comments
8,538 views