I have a PL/SQL block that queries from an empty table. I was wondering is there any way to convert a blank result into 0? or at least us the ifnull function to this query?
Here is the code
declare
p_entity_id varchar2(14) := 10100033904;
date_format varchar2(10) := 'MM/DD/YYYY';
v_mapcount integer;
v_compcount integer;
v_qa_comp_date varchar2(12) := 'MM/DD/YYYY';
begin
SELECT SUM(total),SUM(complete),TO_CHAR(MAX(compDate),date_format) INTO v_mapCount,v_CompCount,v_qa_comp_date FROM
(
SELECT COUNT(barcode) as total, SUM(DECODE(qa_comp,NULL,0,1)) complete ,MAX(qa_comp) compDate from bbsp_boundary WHERE upper(cycle1) = 'Y' AND entity_id = p_entity_id AND DELETED_DATE IS NULL
UNION ALL
SELECT COUNT(barcode) as total, SUM(DECODE(qa_comp,NULL,0,1)) complete ,MAX(qa_comp) compDate from bbsp_feature WHERE upper(cycle1) = 'Y' AND entity_id = p_entity_id AND DELETED_DATE IS NULL
UNION ALL
SELECT COUNT(barcode) as total, SUM(DECODE(qa_comp,NULL,0,1)) complete ,MAX(qa_comp) compDate from bbsp_ADDRESS WHERE upper(cycle1) = 'Y' AND entity_id = p_entity_id AND DELETED_DATE IS NULL
UNION ALL
SELECT COUNT(barcode) as total, SUM(DECODE(qa_comp,NULL,0,1)) complete ,MAX(qa_comp) compDate from bbsp_CORRECTION WHERE upper(cycle1) = 'Y' AND entity_id = p_entity_id AND DELETED_DATE IS NULL
UNION ALL
SELECT COUNT(barcode) as total, SUM(DECODE(qa_comp,NULL,0,1)) complete ,MAX(qa_comp) compDate from bbsp_point_landmark WHERE upper(cycle1) = 'Y' AND entity_id = p_entity_id AND DELETED_DATE IS NULL
UNION ALL
SELECT COUNT(barcode) as total, SUM(DECODE(qa_comp,NULL,0,1)) complete ,MAX(qa_comp) compDate from bbsp_area_landmark WHERE upper(cycle1) = 'Y' AND entity_id = p_entity_id AND DELETED_DATE IS NULL
) ;
end;