Chinaunix
标题:
oracle中查询列插入另外表列的SQL语句
[打印本页]
作者:
c_u_c_u
时间:
2010-11-03 15:13
标题:
oracle中查询列插入另外表列的SQL语句
例如:表A 数据结构如下
id name age...
表B 数据结构如下
id name ....
需求如下,表A的id 和表B的id关联,A的name字段为空,现在要表B的name字段插入到表A的name字段。
sql语句:
1.直接使用update语句操作
update A a set a.name = (select b.name from B b where a.id=b.id)
复制代码
2.使用oracle的merge into 合并操作
merge into A a
using B b
on (a.id = b.id)
when matched then
update set a.name = b.name
复制代码
作者:
renxiao2003
时间:
2010-11-03 17:18
是更新数据啊。我以为楼主要直接更新列名呢。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2