Oracle merge into usage explanation + instance role: merge into solves the problem of using Table B and new table A data. If table A does not exist, the data of Table B is inserted into Table A. 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 tfa_alarm_act_nms ausing (select FP0,FP1,FP2,FP3,REDEFINE_SEVERITYfrom tfa_alarm_status) bon (a.fp0=b.fp0 and a.fp1=b.fp1 and a.fp2=b.fp2 and a.fp3=b.fp3)when matched then update set a.redefine_severity=b.redefine_severitywhen not matched then insert (a.fp0,a.fp1,a.fp2,a.fp3,a.org_severity,a.redefine_severity,a.event_time,a.int_id)values (b.fp0,b.fp1,b.fp2,b.fp3,b.REDEFINE_SEVERITY,b.redefine_severity,sysdate,7777778);
Purpose: Use the tfa_alarm_status table and B of the new table tfa_alarm_act_nms. redefine_severity, condition is. fp0 = B. fp0 and. fp1 = B. fp1 and. fp2 = B. fp2 and. fp3 = B. fp3. If data in the tfa_alarm_act_nms table does not have this condition, it is inserted. If your data volume is large, the SQL efficiency is very high.