Thanks for your answer.can you please add a sample code to remove the
entries with zero count from the v_emp collection?
Picking from your comments, you should pick only those records at first place in your query where count is not zero rather than checking it at later stage. See below.
CREATE TABLE emp(emp_NM VARCHAR2(10),
emp_id NUMBER,
sal NUMBER);
/
INSERT INTO emp VALUES ('X',1,100);
INSERT INTO emp VALUES ('A',2,200);
INSERT INTO emp VALUES('B',3,300);
INSERT INTO emp values ('C',4,400);
/
Select * from emp;
/
CREATE OR REPLACE TYPE ep_id IS TABLE OF NUMBER;
/
DECLARE
Type v_emp IS TABLE OF NUMBER INDEX BY pls_integer;
emp_var v_emp;
--Declared a table having emp_id as in your case where you try to get this in a collection v_emp.
v_ep_id ep_id:=ep_id(1,2,4,5,6);
BEGIN
---Query to select only those records whose count is greater than 0.
SELECT COUNT(emp_id)
bulk collect INTO emp_var
FROM emp
--WHERE emp_id IN (SELECT * FROM TABLE(v_ep_id) ) --< You can use this as well.
WHERE emp_id MEMBER OF v_ep_id
GROUP BY emp_id, sal, emp_nm
HAVING COUNT(emp_id) > 0 ;
--Here you directly do the merge of the selected records which are not Zero
FORALL i IN 1 .. emp_var.Count
MERGE INTO emp1 e1 using dual ON(a.id=b.id)
WHEN MATCHED
//Update statement
WHEN NOT MATCHED
//Insert statement
END IF;
Exception
WHEN others then
raise_application_error(-20001,'Error');
END;