We have two tables one is source and another one is target. The source table gets updated/refresh with external data source and we have a PL/SQL block which runs daily and updates/inserts the target table rows using Oracle's merge function.
Now we have a situation where a column (email) in the target table could get updated by some external source. Consequently, this email is being updated/overwritten by email of source table with the above mentioned PL/SQL's merge function.
Is there something in the merge function so that it only updates the rows in the target table if things other than the email have been changed. I am happy to add new column(s) into the source and target table if needed.
create or replace
PROCEDURE INSERT_UPDATE_TARGET AS
BEGIN
merge into INTEGRATION_TARGET t
using v_merge vm
on (t.person_num = vm.person_num)
when matched then update set T.YEAR_START = VM.YEAR_START,
T.SEMESTER_START = VM.SEMESTER_START,
T.SATAC_DATABASE_NAME = VM.SATAC_DATABASE_NAME,
T.STUDY_LEVEL = VM.STUDY_LEVEL,
T.REF_NUM = VM.REF_NUM,
T.SEX = VM.SEX,
T.DATE_OF_BIRTH = VM.DATE_OF_BIRTH,
T.DATE_RECEIVED = VM.DATE_RECEIVED,
T.TITLE = VM.TITLE,
T.FAMILY_NAME = VM.FAMILY_NAME,
T.GIVEN_NAME_1 = VM.GIVEN_NAME_1,
T.STREET_NAME = VM.STREET_NAME,
T.STREET_NAME_2 = VM.STREET_NAME_2,
T.STREET_NAME_3 = VM.STREET_NAME_3,
T.POSTAL_STATE = VM.POSTAL_STATE,
T.POSTAL_TOWN = VM.POSTAL_TOWN,
T.POSTAL_POSTCODE = VM.POSTAL_POSTCODE,
T.COUNTRY = VM.COUNTRY,
T.MOBILE = VM.MOBILE,
T.EMAIL = VM.EMAIL
when not matched then insert (T.YEAR_START,
T.SEMESTER_START,
T.SATAC_DATABASE_NAME,
T.STUDY_LEVEL,
T.REF_NUM,
T.PERSON_NUM,
T.SEX,
T.DATE_OF_BIRTH,
T.DATE_RECEIVED,
T.TITLE,
T.FAMILY_NAME,
T.GIVEN_NAME_1,
T.STREET_NAME,
T.STREET_NAME_2,
T.STREET_NAME_3,
T.POSTAL_STATE,
T.POSTAL_TOWN,
T.POSTAL_POSTCODE,
T.COUNTRY,
T.MOBILE,
T.EMAIL
)
values(VM.YEAR_START,
VM.SEMESTER_START,
VM.SATAC_DATABASE_NAME,
VM.STUDY_LEVEL,
VM.REF_NUM,
VM.PERSON_NUM,
VM.SEX,
VM.DATE_OF_BIRTH,
VM.DATE_RECEIVED,
VM.TITLE,
VM.FAMILY_NAME,
VM.GIVEN_NAME_1,
VM.STREET_NAME,
VM.STREET_NAME_2,
VM.STREET_NAME_3,
VM.POSTAL_STATE,
VM.POSTAL_TOWN,
VM.POSTAL_POSTCODE,
VM.COUNTRY,
VM.MOBILE,
VM.EMAIL
);
END;
Thanks