Oracle merge into usage details + instances

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.