When doing a MERGE in Oracle SQL, how can I update rows that aren't matched in the SOURCE?

前端 未结 4 1499
心在旅途
心在旅途 2021-02-05 12:59

I have a main database and a report database, and I need to sync a table from main into report.

However, when an item

4条回答
  •  独厮守ぢ
    2021-02-05 13:36

    The following answer is to merge data into same table

    MERGE INTO YOUR_TABLE d
    USING (SELECT 1 FROM DUAL) m
        ON ( d.USER_ID = '123' AND d.USER_NAME= 'itszaif') 
    WHEN NOT MATCHED THEN
            INSERT ( d.USERS_ID, d.USER_NAME)
            VALUES ('123','itszaif');
    

    This command checks if USER_ID and USER_NAME are matched, if not matched then it will insert.

提交回复
热议问题