有个表A有字段ID, NAME
有个表B有字段ID,NEWNAME 都是百万级的数据
现在我要将A里面的ID在B里面存在的数据取出来
然后将取出来的数据的 NEWNAME设置成A的NAME 如何高效呢?我是这样写的
cursor c_id is select * from B where id in (select id from A)
然后用fetch 游标循环
在循环里面 update a set name = v_name where id = v_id
(v_name , v_id 是游标的值)这样是对的 但是效率不高 请问有高效率的吗
有个表B有字段ID,NEWNAME 都是百万级的数据
现在我要将A里面的ID在B里面存在的数据取出来
然后将取出来的数据的 NEWNAME设置成A的NAME 如何高效呢?我是这样写的
cursor c_id is select * from B where id in (select id from A)
然后用fetch 游标循环
在循环里面 update a set name = v_name where id = v_id
(v_name , v_id 是游标的值)这样是对的 但是效率不高 请问有高效率的吗
解决方案 »
- sql查找出数据表中第30到第40条记录
- pl/sql更新无效
- 修改表数据问题.在线等,谢谢.
- 求助:ASP怎样从oracle的存储过程获取多个返回参数!
- 未找到oracle客户端和网络组件
- 是专找 有两种以上商品的供应商 A这样的供应商很多
- 在线:数据库方案问题
- 从oracle导数据导sqlserver中,某些权限如system/sys下的表在sqlserver的dts中看不见
- 高分求救!客户端和两台oracle服务器的连接的汉字乱码问题!
- 一个小小的查询就是出错~!高手速来帮忙~!
- PLSQL工具有个可是把SQL代码格式化那个在哪里啊?
- 虚心求教一个异常的解决方案: ORA-00937: not a single-group group function
set name = (select newname from b where b.id = a.id)
where exists (select null from b where b.id = a.id)
最高效的方法是使用oracle bucket,可以批量更新...
update a
set name = (select newname from b where b.id = a.id)
where exists (select 1 from b where b.id = a.id)
重复的时候,得稍加改进
select a.id,nvl(b.NEWNAME,a.NAME) from a,b
where a.id = b.id(+);
truncate table a;
insert into a
select * from temp;
drop table temp;
先导出两张表的数据,然后通过shell脚本进行处理后,在导入就ok啦。
update a
set name = (select newname from b where b.id = a.id)
where exists (select 1 from b where b.id = a.id)
还要判断一些值才UPDATE。比如 A里面有两个字段 VALUE1 VALUE2
我取得B的两个字段 TIAOJIAN VALUE
我要判断 TIAOJIAN == 1 就updae A 的VALUE1字段
TIAOJIAN == 2 就updae A 的VALUE2字段
这样还可以批量更新吗
用2个update搞掂,最好不要用游标
update /*+bypass_ujvc*/
(select a.name,b.newname from a,b where b.id = a.id)
set name=newname;
set b.newname=a.name
where exist(select 1 from a where a.id=b.id)
update b
set b.newname=(select a.name from a where a.id=b.id)
where exist(select 1 from a where a.id=b.id)
另外,用游标也是很慢的
-- 支持这种写法
update a
set name = (select NEWNAME from b where a.id = b.id)
where exist (select 1 from b where a.id = b.id);