2012-07-25 49 views
0

让我试着解释我的情况,我有两个表,每个表都包含两个感兴趣的字段,即act_num和identity。第一个表包含两个字段的数据,但第二个表包含用于act_num的数据,没有用于标识的数据。我试图编写一个查询,以便如果第二个表中的act_num等于第二个表中的act_num,那么第一个表的标识将导入到第二个表中的相应行中?做这个的最好方式是什么?我必须使用光标吗?从公共字段的另一个表中导入数据

这些表是Oracle表10g,我正在使用forad for oracle for the sql。请帮忙。有点像:

insert into table2 (identity) select identity from table1 
where act_num = select act_num from table2; 

我不需要table1的所有身份数据。我只需要表1和表2中的act_num的身份数据。请帮忙。

回答

1

你可以只更新它基于第一个表,也许一个解决办法是:

update table2 set identity = (select 
    identity from table1 where act_num = table2.act_num); 

这应该是足够的更新从table2table1身份的所有行,其中act_num是与在table1中发现的相同。

+0

感谢您为我绘制这个。 – ErrorNotFoundException 2012-07-25 07:53:11

+0

欢迎您;) – 2012-07-25 07:53:53

0
insert into table2 (identity) 
select identity from table1 
where act_num in(select act_num from table2); 
相关问题