Inserting Records into a Table with Simultaneous Check and Update in Case of Presence in the Receiving Table MERGE in Oracle (MERGE INTO TABLE)
MERGE — Function intended for merging the result of some query into a receiving table, it is not necessary for the field composition to match.
Applied when it is necessary to supplement some table with new data, updating existing data in the table simultaneously.
Implementation:
merge into таблица_приемник t1
using (select * from таблица_источник) t2
on (t1.id = е2.id and t1.parent_id = t2.parent_id)
when matched then
-- Обновляем если совпадение в таблице t1 найдено
update
set t1.info = t2.info
when not matched then
-- Добавляем если совпадение в таблице t1 не найдено
insert
(t1.id, t1.parent_id, t1.info)
values
(t2.id, t2.parent_id, t2.info);
That's it.
Comments (0)
No comments yet.