Oracle把一个表的某个字段更新到另一张表中

第一种方法:

update tablea set column_name1=(select name2 from tableb where tableb.name3=tablea.name1)
只修改一个
update tablea set column_name1=(select name2 from tableb where tableb.name3='a') where tablea.name1='A'

第二种方法:

假设A表有字段ID和NameA,B表有字段ID和NameB,两个表通过ID连接,把NameB更新到NameA,可以这么写:
merge into A
using(select NameB fromB) TMP
on (A.ID=TMP.ID)
when matched then
update set A.NameA=TMP.NameB

第三种方法:(建议使用这个)

  • A表数据

    

  • B表数据

          

  • 现在要把B表 B_COSTS 的值update到A表 A_COSTS 字段
  • SQL语法:

      update a set (a.a_costs) = (select b.b_costs from b where a.id = b.id and a.a_id = b.b_id) where exists
                      (select 1 from b where a.id = b.id and a.a_id = b.b_id)

  • 结果:

    

第四种方法:(更新内嵌视图)

 

update (

select e.sal as emp_sal,  e.comm as emp_comm,  ns.sal as ns_sal,  ns.sal/2 as ns_comm 

from emp e,new_sal ns where e.deptno = ns.deptno

) set emp_sal = ns_sal,emp_comm = ns_comm;

 

  • 18
    点赞
  • 93
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值