用乙個表中的資料更新到另乙個表SQL語句

2021-08-22 09:24:32 字數 2003 閱讀 2204

把同步表:tbl_s1_m7_person_in_phase 中的資料更新基礎表:  tbl_s1_m5_person_info

但這樣關聯的兩個字段必須為主鍵(有唯一性)

/*+ bypass_ujvc */的作用是跳過oracle的鍵檢查。 這樣雖然能夠執行了,但是如果pip_work_no中存在不唯一的資料,pi_work_no 就會被更新多次而導致意想不到的結果

update

(select /*+ bypass_ujvc */

a.pip_name m_name,

b.pi_name n_name,

a.pip_*** m_***,

b.pi_*** n_***,

a.pip_state m_state,

b.pi_state n_state,

a.pip_kind m_kind,

b.pi_kind n_kind,

a.pip_adjust_post m_adjust_post,

b.pi_adjust_post n_adjust_post,

a.pip_enter_date m_enter_date,

b.pi_enter_date n_enter_date,

a.pip_is_subsidy m_subsidy,

b.pi_is_subsidy n_subsidy,

a.pip_identity_card m_identity_card,

b.pi_identity_card n_identity_card,

a.pip_birth_date m_birth_date,

b.pi_birth_date n_birth_date,

pkg_s1_m5_department.get_department_id_by_no(a.pip_department) m_department,

b.pi_di_id n_di_id,

a.pip_stature m_pip_stature,

b.pi_stature n_pip_stature,

b.pi_loader n_loader,

b.pi_load_date n_load_date,

b.pi_modifier n_modifier,

b.pi_modify_date n_modify_date,

b.pi_first_date n_first_date

from

tbl_s1_m7_person_in_phase a,

tbl_s1_m5_person_info b

where

a.pip_work_no = a_work_no

and b.pi_work_no = a_work_no

) tset

t.n_name = t.m_name,

t.n_*** = t.m_***,

t.n_state = t.m_state,

t.n_kind = t.m_kind,

t.n_adjust_post = t.m_adjust_post,

t.n_enter_date = t.m_enter_date,

t.n_subsidy = t.m_subsidy,

t.n_identity_card = t.m_identity_card,

t.n_birth_date = t.m_birth_date,

t.n_di_id = t.m_department,

t.n_pip_stature = decode(t.m_pip_stature, null, t.n_pip_stature, t.m_pip_stature),

t.n_loader = a_operator,

t.n_load_date = sysdate,

t.n_modifier = a_operator,

t.n_modify_date = sysdate,

t.n_first_date = t.m_enter_date; 

用乙個表去更新另乙個表

朋友今天問我乙個問題 有兩張資料表 bureau area code 和 county code,我想用town code擷取前6位去和county code擷取前6位查詢,查到對應的county name該咋寫?下面先是兩張表結構 1 create table bureau area code 2...

mysql用乙個表更新另乙個表的方法

solution 1 修改1列 update student s,city c set s.ci程式設計客棧ty nam程式設計客棧e c.name where s.city code c.code solution 2 修改多個列 update a,b程式設計客棧 set a.title b.ti...

如何去另乙個表取出資料更新到當前表

sql2000我有表tb1,tb2,tb3 tb1的字段product no,color,product size,orderno,tb2欄位joinno,orderno,product info tb3欄位,product no,product type 那麼我想更新表tb2的字段product ...