标签:style http io ar color os sp for on
declare
/* type card_rec_type is record
( dn_no channel.dn_no%type,
channel_id channel.channel_id%type);
type nested_card_type is table of card_rec_type;
card_tab nested_card_type; */
cursor card_rec is
select dn_no,channel_id from channel;
type nested_card_type is table of card_rec%rowtype;-->基于游标的嵌套表类型
card_tab nested_card_type;
begin
select dn_no,channel_id
bulk collect into card_tab
from channel
where lan_id=7;
forall i in card_tab.first .. card_tab.last
insert into (select dn_no,channel_id from tb_card)
values card_tab(i);
commit;
dbms_output.put_line(‘The total ‘||card_tab.count||‘ has insert into tb_card‘);
end;
/--如果我们在forall抛出异常的时候进行捕获,在Exception处理语句中进行commit的话,我们成功更新的记录是可以保存下来
示例2
declare cursor cur is select object_id,object_name from dba_objects a where a.OBJECT_TYPE=‘TABLE‘; l_count number :=0; l_commit number :=100; type t_target is table of cur%rowtype; l_target t_target; l_limit number default 10; begin open cur; loop fetch cur bulk collect into l_target limit l_limit; exit when l_target.count=0; forall i in l_target.first .. l_target.last insert into tmp_lbx (id,name) values(l_target(i).object_id,l_target(i).object_name); l_count :=l_count + l_target.count; if l_count >= l_commit then commit; l_count :=0; end if; end loop; commit; close cur;end;
declare
type id_list is table of t.object_id%type index by binary_integer;
id_info id_list;
i number;
ERRORS_NUM number;
begin
select object_id
bulk collect into id_info from t;
forall i in id_info.first .. id_info.last save exceptions
update t set subobject_name=object_type||timestamp
where object_id=id_info(i);
commit;
exception
when others then
errors_num :=sql%bulk_exceptions.count;
dbms_output.put_line(‘Total Exception is :‘||to_char(errors_num));
if errors_num > 10 then
errors_num := 10;
end if;
for i in 1 .. errors_num loop
dbms_output.put_line(‘Error #‘||i||‘ is ‘||sql%bulk_exceptions(i).error_index||‘ ‘ ||sqlerrm(-sql%bulk_exceptions(i).error_code));
end loop;
rollback;
end;
/
declare
type id_list is table of t.object_id%type index by binary_integer;
id_info id_list;
i number;
j number;
ERRORS_NUM number;
begin
select object_id
bulk collect into id_info from t;
forall i in id_info.first .. id_info.last save exceptions
update t set subobject_name=object_type||timestamp
where object_id=id_info(i);
for j in id_info.first .. id_info.last loop
dbms_output.put_line(‘Iteration# ‘||j||‘ : ‘||sql%bulk_rowcount(j)||‘ rows.‘);
end loop;
commit;
end;
/
标签:style http io ar color os sp for on
原文地址:http://www.cnblogs.com/bowshy/p/4111775.html