Something like this should work (though I haven't got tables etc to do any testing on).


declare
type tab_precedence is table of varchar2(3) index by binary_integer;
t_prec tab_precedence;
type tab_nonstock is table of tab_precedence index by varchar2(3);
t_nonstock tab_nonstock;
t_val varchar2(3);
function test (p_test in tab_precedence, p_roc in varchar2, p_lan in varchar2,
p_new in varchar2, p_sea in varchar2, p_atl in varchar2) return varchar is
v_val varchar2(3);
begin
for i in 1..5 loop
if p_test(i) = 'ROC' and roc_stocking IN ( 'S', 'M' ) then return 'ROC';
elsif p_test(i) = 'LAN' and roc_stocking IN ( 'S', 'M' ) then return 'LAN';
elsif p_test(i) = 'NEW' and roc_stocking IN ( 'S', 'M' ) then return 'NEW';
elsif p_test(i) = 'SEA' and roc_stocking IN ( 'S', 'M' ) then return 'SEA';
elsif p_test(i) = 'ATL' and roc_stocking IN ( 'S', 'M' ) then return 'ATL';
end if;
end loop;
return null;
end;
begin
-- Initialise
t_prec(1) := 'ROC';
t_prec(2) := 'LAN';
t_prec(3) := 'NEW';
t_prec(4) := 'SEA';
t_prec(5) := null;
t_nonstock('ATL') := t_prec;
t_prec(1) := 'ROC';
t_prec(2) := 'ATL';
t_prec(3) := 'NEW';
t_prec(4) := 'SEA';
t_prec(5) := null;
t_nonstock('LAN') := t_prec;
t_prec(1) := 'SEA';
t_prec(2) := 'ROC';
t_prec(3) := 'ATL';
t_prec(4) := 'LAN';
t_prec(5) := null;
t_nonstock('NEW') := t_prec;
t_prec(1) := 'ATL';
t_prec(2) := 'NEW';
t_prec(3) := 'LAN';
t_prec(4) := 'SEA';
t_prec(5) := null;
t_nonstock('ROC') := t_prec;
t_prec(1) := 'NEW';
t_prec(2) := 'ROC';
t_prec(3) := 'ATL';
t_prec(4) := 'LAN';
t_prec(5) := null;
t_nonstock('SEA') := t_prec;
t_prec(1) := 'ROC';
t_prec(2) := 'LAN';
t_prec(3) := 'ATL';
t_prec(4) := 'SEA';
t_prec(5) := 'NEW';
t_nonstock('TOR') := t_prec;
-- Body
t_prec := t_nonstock(sku_rec.loc);
t_val := test(t_prec,roc_stocking,lan_stocking,new_stocking,sea_stocking,atl_stocking);
if t_val is not null then
INSERT INTO stsc.temp_q_sku2
SELECT * from stsc.sku
where item = sku_rec.item
and loc = t_val;
else
DELETE FROM stsc.temp_q_sku1
WHERE CURRENT OF sku_cur;
end if;
end;