create table catalog1 (id number(3), item varchar2 (20), price number(6))
Table created.
insert into catalog1 values(1, 'laptop', 800)
1 row(s) inserted.
insert into catalog1 values(2, 'iphone', 500)
1 row(s) inserted.
insert into catalog1 values(3, 'camera', 700)
1 row(s) inserted.
select * from catalog1
ID | ITEM | PRICE |
---|---|---|
1 | laptop | 800 |
2 | iphone | 500 |
3 | camera | 700 |
create table catalog2 (id number(3), item varchar2 (20), price number(6))
Table created.
insert into catalog2 values(1, 'laptop', 899)
1 row(s) inserted.
insert into catalog2 values(2, 'iphone', 599)
1 row(s) inserted.
insert into catalog2 values(5, 'video camera', 799)
1 row(s) inserted.
select * from catalog2
ID | ITEM | PRICE |
---|---|---|
1 | laptop | 899 |
2 | iphone | 599 |
5 | video camera | 799 |
MERGE INTO catalog1 s1 USING catalog2 s2 ON (s1.id = s2.id)
WHEN MATCHED THEN UPDATE SET s1.price = s2.price
WHEN NOT MATCHED THEN INSERT (id, item, price) values (s2.id, s2.item, s2.price)
3 row(s) updated.
select * from catalog1
ID | ITEM | PRICE |
---|---|---|
1 | laptop | 899 |
2 | iphone | 599 |
3 | camera | 700 |
5 | video camera | 799 |