Grammar:
MERGE into [Your table-name] [rename your table here]
USING ([Write your query here]) [Rename your and Query-sql G just like a table] on
([conditional expression here] and [...] ...)
When mathed THEN [I can execute some update SQL or something else] when not
mathed THEN [Execute something Els e here! ]
Instance:
Merge into Tfa_alarm_act_nms a
using (select Fp0,fp1,fp2,fp3,redefine_severity from
tfa_alarm_status) b
On (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.re Define_severity when not
matched then insert (a.fp0,a.fp1,a.fp2,a.fp3,a.org_severity,a.redefine_severity,
A.event_time , a.int_id)
Function: Use table Tfa_alarm_status to Tfa_alarm_act_nms b.redefine_severity with new table, provided a.fp0=b.fp0 and A.FP1=B.FP1 and A.FP2=B.FP2 and A.FP3=B.FP3, if the data in the TFA_ALARM_ACT_NMS table does not have the condition inserted.
If you have a large amount of data, this SQL efficiency is very high.
Turn from: http://azrael6619.iteye.com/blog/759678