Say I have the table XX_TABLE_SAMPLE
with the records below:
TAB_ID BATCH_NAME EMP_NO EMP_NAME STATUS SALARY CATEGORY
------ ---------- ------ -------- -------- ------- ------------
1 BATCH_A 1 Jared Active 1000 (NULL)
2 BATCH_A 2 Siege Active 3000 (NULL)
3 BATCH_A 45 James Suspended 2000 (NULL)
4 BATCH_B 67 Harry Active 100 (NULL)
5 BATCH_B 99 Pikachu Active 10000 (NULL)
6 BATCH_x 100 Eren Suspended 4000 (NULL)
and i have the PL/SQL block like below (please note the comments):
declare
cursor emp_cur is
select *
from XX_TABLE_SAMPLE
where status = 'Active';
type emp_cur_type is table of XX_TABLE_SAMPLE%rowtype index by pls_integer;
emp_rec emp_cur_type;
begin
open emp_cur;
fetch emp_cur
bulk collect
into emp_rec;
close emp_cur;
/* do some pre-processing here via another stored procedure
but the problem is, it has a parameter of p_batch_name, not a type of associative array
for i in emp_rec.first..emp_rec.last loop
pay_pkg.validate_pay (p_batch_name => emp_rec(i).p_batch_name);
end;
-- the problem with this is that it will loop 4 times (twice each for BATCH_A and BATCH_B)
when it should only get the 2 batch names (BATCH_A and BATCH_B)
*/
-- then check the salary of the emp and update the associative array
for i in emp_rec.first..emp_rec.last loop
if emp_rec(i).salary > 200 and emp_rec(i).salary < 3000 then
emp_rec(i).CATEGORY = 'Manager';
end if;
end loop;
forall i in emp_rec.first..emp_rec.last
update XX_TABLE_SAMPLE
set CATEGORY = emp_rec(i).CATEGORY
where TAB_ID = emp_rec(i).TAB_ID;
end;
With that, I would like to get the distinct values of the Element Batch_Name
in an Associative Array
and then pass it to the Stored Procedure pay_pkg.validate_pay
.
Any thoughts on how i can achive this without declaring another Explicit Cursor?