1. 程式人生 > >oracle 一個表新增多個欄位,根據條件重新整理欄位值

oracle 一個表新增多個欄位,根據條件重新整理欄位值

2. Oracle

  1. update TA a set(name, remark)=(select b.name, b.remark from TB b where b.id=a.id)   
  2. where exists(select 1 from TB b where b.id=a.id)  

注意如果不新增後面的exists語句,TA關聯不到的行name, remark欄位將被更新為NULL值, 如果name, remark欄位不允許為null,則報錯。 這不是我們希望看到的。

  1. --when name, remark is not null, cause error. 
  2. --if allow null, rows in TA not matched will be update to null.
  3. update TA a set(name, remark)=(select b.name, b.remark from TB b where b.id=a.id);