union all WITH merge into using update or insert ???
645300Oct 1 2009 — edited Oct 2 2009THERE ARE THREE TABLES TABLE1, TABLE2 AND DIS_TABLE(3rd table) WITH SAME FIELDS NAMES.
Now, table 1 field names are same as dis_table but different data compared to table2
table 2 field names are same as dis_table but different data compared to table1
- now i want to update or insert data into dis_table using table1
- next, again i want to update or insert data into dis_table from table2
All i m trying to do is get the data from table 1 and table 2, do update or insertion into dist_table(3rd table)based on conditions.
below is the structure of the code which i m planning to do for above task.
create or replace procedure dist_insert
is
begin
( merge into dist_table d
using ( select * from table1) ins1
on ( d.pkey = ins1.pkey
and d.job_id = ins1.job_id)
when matched then
update set ( ------ ----- ---------)
when not matched then
insert into (---------)
values (-------)
)
union all
( merge into dist_table d
using ( select * from table2) ins2
on ( d.pkey = ins2.pkey
and d.jobid = ins2.job_id)
when matched then
update set ( -------- ------ --)
when not matched then
insert into (---- --- -----)
values( ------)
);
commit;
end;
My questions
- is this right approach for updating or inserting the records from 2 table's into the the 3rd table.
- can i use union all with the two merge's, which i m trying to do above ??
- OR alternative approach is writing two cursors for each table then later insert using for loop for each table in begin end block; is this right approach again ???
- if not do u guys have any suggestions or different approach ????
Thank you so much!!!