【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:通过判断条件更新数据库某个字段的值
还没有评论,来说两句吧...