我现在要做数据移行,从文本中读取20W条数据到零时表A中,需要将这20W条数据更新到B表,B中数据量超过100W条,原有思路是对A表进行循环将数据更新到B表中,但此方法效率太低。能不能按A表中的某个字段对数据进行并发更新?例如:A表中有地区号字段,根据地区号不同对B表进行同时update处理!往高手指点啊!说得越详细越好,最好能有详细的例子!
解决方案 »
- ora 12528出错所有适用实例都无法建立连,急需解决下
- 还是昨天的union链接问题,××××在线等待×××××
- 存储过程中诸如UTL_RAW.CAST_TO_RAW这样的包函数哪里能找到相关说明?oracle sql reference里怎么搜不到?
- 求简单SQL语句~~~~~~~~~~~~急,再线等
- 急急急!!!oracle的入门教材(电子版)
- Oracle连接会话数的问题
- 如何从一个dmp文件中提取一个表并以dbf文件存储?
- 关于2个表联合查询出不相同的记录集?
- Oracle816实例不能启动
- 请教大神,EXPDP导出数据库到客户端
- oracle 数据库迁移
- pl/sql如何导出/导入表数据,
merge into a
using (select id,name from b ) c
on(a.id=c.id )
when matched then update set a.name=c.name
when not matched then insert (a.id,a.name) values (c.id,c.name);
作用:利用表 b 跟新表a ,条件是a.id=b.id,如果a表中没有该条件的数据就插入。如果你的数据量很大,此sql效率非常高。
存储过程使用临时表的例子:create or replace procedure upd_wbb_quotenum
as
begin
--创建会话级临时表
execute immediate 'CREATE GLOBAL TEMPORARY TABLE tmp_wbb_quotenum (project_id NUMBER,quotenum NUMBER) ON COMMIT PRESERVE ROWS'; --找出第一个SQL需要的count及projectid,插入临时表数据
insert into tmp_wbb_quotenum
select project_id,count(distinct seller_id)
from bid_quote_tables
where status >= 5
group by project_id; --关联临时表进行修改
update web_business_bulletin a
set a.quotenum = tmp_wbb_quotenum.quotenum
where a.itemState = 1
and (a.bulletinType = 1 or a.bulletinType = 2)
and a.projectid = tmp_wbb_quotenum.project_id;
--提交
commit; --清空临时表
execute immediate 'truncate table tmp_wbb_quotenum'; --找出第二个SQL需要的count及projectid,插入临时表数据
insert into tmp_wbb_quotenum
select projectid,count(distinct selleruserid)
from expr_bid_quotetable
group by projectid; --关联临时表进行修改
update web_business_bulletin a
set a.quotenum = tmp_wbb_quotenum.quotenum
where a.itemState = 1
and (a.bulletinType = 30 or a.bulletinType = 31)
and a.projectid = tmp_wbb_quotenum.project_id;
--删除临时表
execute immediate 'drop table tmp_wbb_quotenum';
commit;
exception when others then
raise;
end upd_wbb_quotenum;
/
if tempisexist=0 then--不存在临时表就创建一个
execute immediate 'grant create table to upd_wbb_quotenum';--还得给存储过程中加上增加表的权限。
刚在别处看了个例子,最好在建表前加个判断