【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:通過判斷條件更新數據庫某個字段的值

發佈了113 篇原創文章 · 獲贊 77 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章