oracle sql更新字段为另一张表的对应字段

[复制链接]
查看11 | 回复2 | 2012-9-23 19:23:58 | 显示全部楼层 |阅读模式
首先你的语句有点问题,应该这样写:update table_1 t1 set t1.name=(select t2.name from table_2 where t1.id=t2.id) where exists (select 1 from table_2 where t1.id=t2.id)and t1.idcard ='1111';之前子查询中的 t1.idcard ='1111' 是多余的。exists子句中的 t1.idcard ='1111'应该拿到外边来。 如果这样还是慢的话,那就是你的索引项建的有问题了,需要把两个表中的id作为索引,还有就是idcard也可以建索引。这样就好了。...
回复

使用道具 举报

千问 | 2012-9-23 19:23:58 | 显示全部楼层
我觉得应该使用merge比较好merge intotable_1 t1 using table_2 t2on(t1.id=t2.id and t1.idcard ='1111')when matched thenupdate name=t2.name;自己手动敲得没有验证,如不懂用法的话可以百度merge用法看一下就会了...
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行