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

墨蓝 2023-07-01 06:30 78阅读 0赞

需求

更新表中的N个字段的值

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

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

方法

更新多个字段

  1. -- 方法一
  2. update a set a.province=(select province from b where b.mobile=a.mobile);
  3. update a set a.city=(select city from b where b.mobile=a.mobile);
  4. -- 方法二
  5. update a set a.province=b.province,a.city=b.city from a,b where a.mobile=b.mobile;
  6. update a set a.province=b.province,a.city=b.city from a inner join b on a.mobile=b.mobile;
  7. -- 方法三
  8. update a inner join b on a.mobile=b.mobile set a.province=b.province,a.city=b.city;
  9. -- 方法四(最优)
  10. update a set(a.province,a.city)=(select province,city from b where b.mobile=a.mobile);

根据条件更新字段

  1. update t_cure_plan a
  2. set (inject) =
  3. (select case
  4. when inject = '第一针' then
  5. '1'
  6. when inject = '第二针' then
  7. '2'
  8. else
  9. inject
  10. end as newInject
  11. from t_cure_plan b
  12. where a.id = b.id);

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

发表评论

表情:
评论列表 (有 0 条评论,78人围观)

还没有评论,来说两句吧...

相关阅读