declare
type yy_assign_type is table of yy_assign_tbd20091001%rowtype index by binary_integer;
type customer_list_type is table of custmer_list_tbd20091001%rowtype index by binary_integer;
V_SALES_ID VARCHAR2(32);
v_num pls_integer := 0;
v_mod_num pls_integer:=0;
old_num pls_integer:=0;
yy_assign_table yy_assign_type;
customer_list_table customer_list_type;
begin
select yy.* bulk collect
into yy_assign_table
from yy_assign_tbd20091001 yy
where yy.res_type ='idsType' and rownum<500
order by yy.serial_num;
select * bulk collect
into customer_list_table
from custmer_list_tbd20091001
where customer_type ='X' ORDER BY sales_id;
for i in 1 .. yy_assign_table.count loop
if(yy_assign_table(i).SERIAL_NUM = old_num) then
update yy_assign_tbd20091001 set is_used='y',CUSTOMER_ATTR=V_SALES_ID where member_id = yy_assign_table(i).MEMBER_ID;
else
v_mod_num :=mod(i,customer_list_table.count);
if(v_mod_num=0) then
v_mod_num:= customer_list_table.count;
end if ;
V_SALES_ID :=customer_list_table(v_mod_num).SALES_ID;
update yy_assign_tbd20091001 set is_used='y',CUSTOMER_ATTR=V_SALES_ID where member_id = yy_assign_table(i).MEMBER_ID;
old_num :=yy_assign_table(i).SERIAL_NUM ;
end if ;
dbms_output.put_line(yy_assign_table(i).SERIAL_NUM);
end loop;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
Dbms_Output.put_line('error encounter');
ROLLBACK;
END;
覺得這個辦法比以前的for 迴圈好了很多 就自己想了一下 寫寫