2012-07-25 88 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); 
相關問題