I have a simple delete procedure which is using na cursor. I read somewhere that table vars should be preferred to cursors.
CREATE OR REPLACE PROCEDURE SMTAPP.LF_PLAN_VYMAZ (Str_oz varchar2, Num_rok number, Num_mesiac number, Str_s_trc_id varchar2) IS
var_LF_PLAN_ID Number(20);
cursor cur_plan is select id from lp_plan where lf_plan_id=var_LF_PLAN_ID;
BEGIN
select ID into var_LF_PLAN_ID from lf_plan where oz=Str_oz and rok=Num_rok and mesiac=Num_mesiac and s_trc_id=Str_s_trc_id;
for c1 in cur_plan loop
delete from LP_PLAN_DEN where lp_plan_id=c1.id;
end loop;
delete from LP_PLAN where lf_plan_id=var_LF_PLAN_ID;
delete from LP_PLAN_HIST where LF_PLAN_ID=var_LF_PLAN_ID;
delete from LF_PLAN where id=var_LF_PLAN_ID;
END;
I don’t know what a “table var” is (I have a feeling it is a SQL Server term?) but I would not use a cursor here, I would do this:
EDIT: “Table var” is indeed a SQL Server concept
I would code this as shown above, however since you specifically want to see how to do it with a collection, here is another way that uses one:
This will probably not perform as well as the previous method.