- 作者: 三十而立
- 时间:2009年10月09日 21:30:04
- 本文出自 “inthirties(三十而立)”博客,转载请务必注明作者和保留出处http://blog.csdn.net/inthirties/archive/2009/10/09/4644405.aspx
有时候我们需要update一个表中的多个字段,通过子查询的方式。
这里可以用一下的方式。
update A set (person_name,cetf_id)=(select person_name,cetf_id from 表B b
where a.person_id = b.person_id )
或者用merge into的用法,呵呵呵,有点多余,不过这里主要是看看merge的用法而已
merge into a
using b
on (a.person_id=b.person_id)
when matched then
update set a.person_name=b.person_name,a.cetf_id=b.cetf_id
when not matched then
insert (person_name,cetf_id) values (b.person_name,b.cetf_id);
- 如果没有那句“三十而立”,三十岁的男人正可以轻轻松松
- 专业论坛 http://www.inthirties.com
- 技术博客 http://blog.csdn.net/inthirties
- 个人站点 http://blog.inthirties.com
- Oracle Mysql技术论坛| 打造实用的Oracle Mysql技术交流园地