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!

Overcome NO ROWS returned in subqueries

831088Jan 13 2011 — edited Jan 14 2011
I have a procedure that inserts values extracted from multiple sub-queries. My question is that if even one of the sub queries returns no rows, the entire insert statement evaluates to nothing and no row is inserted. For example, if sub queries A & B return a valid row but sub query C returns no row, the overall insert statement does not insert anything.

I tried using NVL function, but this works only if a NULL is returned. What if NO ROWs are returned? How do I replace it with a zero value?


create or replace procedure SP_new is
begin
insert into TB_new

select to_date('01/10/2010','MM/DD/YYYY') as cur_date,
A.vol,A.net, B.vol,B.net, C.vol, C.net

from

(select cur_date, sum(vol) as vol, sum(vol)-sum(sell) as net
from tabA
where cur_date = to_date('01/10/2010','MM/DD/YYYY') and rate = 1)A,

(select cur_date, sum(vol) as vol, sum(vol)-sum(sell) as net
from tabA
where cur_date = to_date('01/10/2010','MM/DD/YYYY') and rate = 1)B,

(select cur_date, sum(vol) as vol, sum(vol)-sum(sell) as net
from tabA
where cur_date = to_date('01/10/2010','MM/DD/YYYY') and rate = 1)C,

commit;
end SP_new;


Thanks,
SM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 11 2011
Added on Jan 13 2011
10 comments
2,575 views