create or replace procedure pp_temp2 is--用于根据某个表的数据来更新一张大表的某个字段
cursor cur is --从参考表中获取需要的字段,包括待更新的字段和关联字段
select column1,column2,column3
from schema_name.bi_1_tkt t;--可以添加dblink
type typ_column1 is table of tab_1.column1%type;--以下三句根据列格式定义三种类型的集合
type typ_column2 is table of tab_1.column2%type;
type typ_column3 is table of tab_1.column3%type;
lis_column1 typ_column1; --以下三句创建与列类型对应的集合实例
lis_column2 typ_column2;
lis_column3 typ_column3 ;
n_count number; --用于存储数量
begin
open cur;--开启游标
loop
fetch cur bulk collect--每批1000条,将数据分批fetch
into lis_column2,lis_column1,lis_column3 limit 1000;
n_count:=lis_column2.count;
forall i in lis_column2.first .. lis_column2.last--用forall语句更新
update tab_1
set column3=lis_column3(i)
where tab_1.column2=lis_column2(i)
and tab_1.column1=lis_column1(i)
and tab_1.bsp_code = 'XX';
commit;
exit when n_count=0;
end loop;
close cur;--关闭游标,结束程序
end;
cursor cur is --从参考表中获取需要的字段,包括待更新的字段和关联字段
select column1,column2,column3
from schema_name.bi_1_tkt t;--可以添加dblink
type typ_column1 is table of tab_1.column1%type;--以下三句根据列格式定义三种类型的集合
type typ_column2 is table of tab_1.column2%type;
type typ_column3 is table of tab_1.column3%type;
lis_column1 typ_column1; --以下三句创建与列类型对应的集合实例
lis_column2 typ_column2;
lis_column3 typ_column3 ;
n_count number; --用于存储数量
begin
open cur;--开启游标
loop
fetch cur bulk collect--每批1000条,将数据分批fetch
into lis_column2,lis_column1,lis_column3 limit 1000;
n_count:=lis_column2.count;
forall i in lis_column2.first .. lis_column2.last--用forall语句更新
update tab_1
set column3=lis_column3(i)
where tab_1.column2=lis_column2(i)
and tab_1.column1=lis_column1(i)
and tab_1.bsp_code = 'XX';
commit;
exit when n_count=0;
end loop;
close cur;--关闭游标,结束程序
end;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26451536/viewspace-761935/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26451536/viewspace-761935/