Oracle中,如果跨兩個表進行更新,Sql語句寫成這樣,Oracle 不會通過。查了資料,Sql語句需要這樣寫才行
前提條件:
表info_user中有字段id和name,字段id為索引
表data_user_info中有字段id和name,字段id為索引
其中表info_user中字段id和表data_user_info中字段id數(shù)值一致。
要求實現(xiàn):
更新表info_user中的字段name 與表data_user_info中字段name一致。
實現(xiàn)的SQL語句為:
update info_user i set (i.name) = (select d.name from data_user_info d where d.id = i.id)
where i.id = (select d.id from data_user_info d where d.id = i.id);
commit;
-------------------------分割線-------------------------
Oracle中,如果跨兩個表進行更新,Sql語句寫成這樣
Update Table a set a.ID=Table2.ID where a.Name = Table2.Name
Oracle 不會通過。查了資料,,Sql語句需要這樣寫才行
Update Table a set a.ID=(select b.ID from Table2 b where b.Name = a.Name ) where exist (select 1 from Table2 b.Name=a.Name)
更新多個字段也可以
Update Table a set a.ID=(select b.ID from Table2 b where b.Name = a.Name ),a.Code=(select b.Code from Table2 b where b.Name = a.Name ) where exist (select 1 from Table2 b.Name=a.Name)
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com