问下这个语句怎么写啊、????着急 在线等!!!!!!

zhuzhusex7983 2012-09-03 03:33:08
表A(ID1,VALUE)
表B(ID2,ID3)

描述:我想批量更新表A的所有value字段, 如果ID1=ID2, 就把 id3更新到value字段


常规方法:
update a
set a.value= (select id3 from b where a.id1 = b.id2)
where exists (select 1 from b where a.id1 = b.id2 )

但是表中的数据有几千万,,,到不过来的,,,请问能不能用循环更新1000个提交一次a ???


SQL语句应该怎么写啊?
...全文
105 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
人生无悔 2012-09-03
  • 打赏
  • 举报
回复

--加这句比较好,毕竟你不是所有的都需要更新
update a
set a.value= (select id3 from b where a.id1 = b.id2)
where exists (select 1 from b where a.id1 = b.id2 and a.value<>b.value)
fw0124 2012-09-03
  • 打赏
  • 举报
回复
过程的语法错误,我看到你另外发贴了,就不说了,
你这样循环,效率比单个update语句更差的。
zhuzhusex7983 2012-09-03
  • 打赏
  • 举报
回复
我写了一个,,报错
declare
v_id number;
v_item_id number;
v_frame_id number;
CURSOR cur_cursor
is
select EXAM_RESULT_ITEM_ID,exam_result_item_id from the_d_exam_result_item;
begin
open cur_cursor;
loop
fetch cur_cursor into v_id,v_item_id;
if ( select count(1) from the_d_exam_result_frame where exam_result_item_id = v_frame_id))>0 then
select exam_result_frame_id into v_frame_id from the_d_exam_result_frame where exam_result_item_id = v_frame_id;
end if;
update the_d_exam_result_item set exam_result_id= v_frame_id where EXAM_RESULT_ITEM_ID = v_id;
commit;
exit hen cur_cursor%notfound;
end loop;
end;


请问怎么错了啊,,我ORACLE不太熟

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧