oracle中联接两张表更新字段

两张表)
A、B两表
A表:typecode typename
1 0101
2 0601
3 0301
4 0501
B表: dm mc
1 0101 长城
2 0201 大地
3 0301 故宫
说明:联接A、B两格,当A中typecode出现的值等于B中dm的值时,A表typename的值等于B表的mc。在pl/sql中怎么写?

方法如下:

有以下两张表:

根据test2表中的id和test1表中的id关联,修改test1表中name字段,语句如下:

update test1 a set a.name=(select b.name from test2 b where a.id=b.id) where a.id in (select id from test2);

更新后,test1表中结果:

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-02-27
update a set a.typename=(select b.mc from b where a.typecode=b.dm) where a.typecode in (select dm from b)本回答被提问者和网友采纳
第2个回答  2011-09-14
update A a set a.typename=nvl((select b.mc from B b where b.dm=a.typecode and rownum=1) ,'');
第3个回答  2011-09-14
直接 update a set a.typename=nvl((select top 1 b.mc from b where a.typecode=b.dm),'')
相似回答