MERGE INTO A USING B ON ( A.tiaoma=B.tiaoma )--Conditional association between A table and B table WHEN MATCHED THEN -- perform an update operation if it exists UPDATE SET A.num= B.num WHEN NOT MATCHED THEN -- perform an insert operation if it does not exist. INSERT(num) VALUES(B.num);
Note: The data in table B cannot have duplicate data.
Otherwise ORA-30926: Unable to get a stable set of rows in the source table error.
The internal processing of merge into is to compare and match each record in table A with each record in table B, and the records that match the conditions will be modified, and if they are not matched, they will be inserted. If there are duplicate values in the matching column of table A , when the second duplicate column value matches, the value after the first update will be updated again, that is to say, the merged B will be lost in A in the record! ! ! What's the point of merging two tables if the records are missing? ! ! Therefore, we use merge into to pay attention: there must be no duplicate values in the matching column of the source table, otherwise it cannot be matched (error!).