Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Merge Statement to insert data into target table, only if data exists in Source table

Sreelatha PragadapatiSep 18 2017 — edited Sep 19 2017

declare
Input_ID  varchar2(5):='12345';
value1 varchar2(10):='ABCDEFGHIJ';
begin
Merge into Target
using (select ID from TableAAA where ID = Input_ID ) Source
on (Target.ID= Source.ID)
when matched then
update set col1 = value1
when not matched insert (col1) values (value1);
end;

The above merge statement, checks if ID in target, matches with ID from source and inserts if match not found in Target. I want to insert a record in target, if the ID found in Source, but not in Target.
And I don't want to insert anything in Target, if match not found from Source. How can I achieve it.
Thanks for the suggestions in advance.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2017
Added on Sep 18 2017
8 comments
2,532 views