Insert the record in one table from another table with some criteria in oracle -
i need insert record 1 table table exact replica of other table ,condition putting when same record (for condition match) coming table update existing record , when brand new record come insert record.
i have written query below please correct me if possible.
insert temp1 (b,c,d,provider_id,national_provider_identifier,taxonimy_code,f,g,h) select w.b,w.c,w.d,w.provider_id,w.national_provider_identifier,w.taxonimy_code,w.f,w.g,w.h temp2 w left join temp1 on( a.provider_id = w.provider_id , a.national_provider_identifier = w.national_provider_identifier , a.taxonomy_code = w.taxonomy_code) w.source_id = 'cosmos'
it's still bit unclear me, sound want using merge statement.
if so, statement (hoping understood data model)
merge temp1 using ( select b,c,d,provider_id,national_provider_identifier,taxonimy_code,f,g,h temp2 source_id = 'cosmos' ) w on (a.provider_id = w.provider_id , a.national_provider_identifier = w.national_provider_identifier , a.taxonomy_code = w.taxonomy_code ) when matched update set a.b = w.b, a.c = w.c, a.d = w.d, a.f = w.f, a.g = w.g, a.h = w.h when not matched insert (a.b,a.c,a.d,a.provider_id,a.national_provider_identifier,a.taxonimy_code,a.f,a.g,a.h) values (w.b,w.c,w.d,w.provider_id,w.national_provider_identifier,w.taxonimy_code,w.f,w.g,w.h);
Comments
Post a Comment