【Oracle】根据条件更新多个字段的值

需求

更新表中的N个字段的值

1、根据A表字段的值,更新B表字段的值

2、根据条件更新字段的值

方法

更新多个字段

-- 方法一
update a set a.province=(select province from b where b.mobile=a.mobile);
update a set a.city=(select city from b where b.mobile=a.mobile);

-- 方法二
update a set a.province=b.province,a.city=b.city from a,b where a.mobile=b.mobile;
update a set a.province=b.province,a.city=b.city from a inner join b on a.mobile=b.mobile;

-- 方法三
update a inner join b on a.mobile=b.mobile set a.province=b.province,a.city=b.city;

-- 方法四(最优)
update a set(a.province,a.city)=(select province,city from b where b.mobile=a.mobile);

根据条件更新字段

update t_cure_plan a
   set (inject) =
       (select case
                 when inject = '第一针' then
                  '1'
                 when inject = '第二针' then
                  '2'
                 else
                  inject
               end as newInject
          from t_cure_plan b
         where a.id = b.id);

oracle:set表中多个字段
oracle:通过判断条件更新数据库某个字段的值

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值