Oracle merge into usage example
Purpose:Merge into solves the problem of using data from Table B and new table A. If table A does not exist, the data from Table B is inserted into Table;
Syntax:
Merge into [your table-name] [rename your table here]
Using ([write your query here]) [rename your query-SQL and using just like a table]
On ([conditional expression here] and [...]...)
When mathed then [here you can execute some update SQL or something else]
When not mathed then [execute something else here! ]
------- Instance -------
Merge into
Using (select ID, name from B) c
On (A. ID = C. ID)
When matched then update set a. Name = C. Name
When not matched then insert (A. ID, A. Name) values (C. ID, C. Name );
Purpose: Use table B and new table A with the condition A. ID = B. Id. If table A does not have this condition, insert the data.
If your data volume is large, the SQL efficiency is very high.