MERGE usage

MERGE INTO TABLE_A T
  USING  TABLE_B T1
  ON (T.STU_NO = T1.STU_NO)
  WHEN MATCHED THEN
    UPDATE
       SET T.NAME = T1.NAME
  WHEN NOT MATCHED THEN
    INSERT
          (STU_NO,
           NAME)
        VALUES
          (T1.STU_NO,
           T1.NAME);

 

Compare all the data in the two tables TABLE_A and TABLE_B, take TABLE_A as the main table, and use the STU_NO field of the two tables as the condition. When the two match, modify the NAME field in TABLE_A. If it does not match, insert the unmatched data in TABLE_B into TABLE_A table.

Note that the conditions after ON cannot be used as conditions and modifications in UPDATE and INSERT.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326314285&siteId=291194637