ITPub博客

首页 > 数据库 > Oracle > Update one table with the data in another table

Update one table with the data in another table

原创 Oracle 作者:pan_tian 时间:2014-07-03 11:51:54 0 删除 编辑

如何用一张表中的数据Update另外一张表的数据。Sample:

UPDATE T1
   SET (C1, C2, C3) =
       (SELECT C1, C2, C3 FROM T2 WHERE T2.USER_ID = T1.USER_ID)
 WHERE EXISTS (SELECT * FROM T2 WHERE T2.USER_ID = T1.USER_ID);
如果没有"Where Exists"部分,则可能会出现的问题:在表T1中有的行,但如果在表T2中没有对应的行,那么值会被更新为NULL。加上"Where Exists"部分,确保只更新两表相匹配部分的数据,不匹配部分,保持原值。

还有一些其他方式的写法:

regarding "Updating a table from another table"

http://stackoverflow.com/questions/4378847/how-to-update-one-table-column-values-with-another-tables-column-values

<!-- Baidu Button BEGIN -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26687597/viewspace-1207551/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Oracle EBS数据库对象(Package,Table,View)的Owner
下一篇: 《蔡康永的说话之道》书摘
请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2012-02-18

最新文章