[Oracle] a plurality of value fields updated according to the conditions

demand

Updates the value in the table of N fields

1, according to the value of Field A, Field B is updated value

2, according to the value of the field condition updating

method

Update multiple fields

-- 方法一
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);

According to the update field conditions

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: a plurality of fields of the set tables
oracle: updating the database by determining the condition of a field value of

Published 107 original articles · won praise 88 · views 260 000 +

Guess you like

Origin blog.csdn.net/Code_shadow/article/details/104043502