分批UPDATE COMMIT怎么写

[复制链接]
查看11 | 回复9 | 2014-12-17 20:04:34 | 显示全部楼层 |阅读模式
我要update一个表的某个字段,10000笔commit一次怎么写 ,谢谢
回复

使用道具 举报

千问 | 2014-12-17 20:04:34 | 显示全部楼层
drop table t ;
create table t as select * from dba_objects;
create index i_t_id on t(object_id);
/
create or replace procedure p_update as
type type_1 is table of t%rowtype index by binary_integer;
va type_1;
cur sys_refcursor;
begin
open cur for 'select *from dba_objects t where owner=''SYS''';
loop
fetch cur bulk collect
into va limit 10000;
exit when va.count = 0;
forall i in 1 .. va.count
update t
set t.object_name = va(i).object_name
where t.object_id = va(i).object_id;
commit;

end loop;
end;
/
调用
exec p_update;复制代码
回复

使用道具 举报

千问 | 2014-12-17 20:04:34 | 显示全部楼层
用fetch bulk commit limit + 批量更新即可
回复

使用道具 举报

千问 | 2014-12-17 20:04:34 | 显示全部楼层
二楼正解
回复

使用道具 举报

千问 | 2014-12-17 20:04:34 | 显示全部楼层
本帖最后由 waky14 于 2013-11-7 20:27 编辑
简单点通俗易懂:
loop
update table
where rownum<=10000;
if sql%found then
commit;
else
exit;
end if;
end loop;
回复

使用道具 举报

千问 | 2014-12-17 20:04:34 | 显示全部楼层
waky14 发表于 2013-11-7 20:26
简单点通俗易懂:
loop
update table

完整点。
我现在连存储过程都不会调啊。


回复

使用道具 举报

千问 | 2014-12-17 20:04:34 | 显示全部楼层
去66狗8 发表于 2013-11-7 20:36
完整点。
我现在连存储过程都不会调啊。

loop
update table
set comlumn1=你要修改后的值
where rownum<=10000;
if sql%found then
commit;
else
exit;
end if;
end loop;
回复

使用道具 举报

千问 | 2014-12-17 20:04:34 | 显示全部楼层
去66狗8 发表于 2013-11-7 20:36
完整点。
我现在连存储过程都不会调啊。

6狗,你出山啦
回复

使用道具 举报

千问 | 2014-12-17 20:04:34 | 显示全部楼层
waky14 发表于 2013-11-7 20:41
loop
update table
set comlumn1=你要修改后的值

兄台,你这有问题的啊,哈哈
回复

使用道具 举报

千问 | 2014-12-17 20:04:34 | 显示全部楼层
waky14 发表于 2013-11-7 20:41
loop
update table
set comlumn1=你要修改后的值


把create 到call全部写一遍。我自己写的把你的贴进去有个XX调不起来
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行